In this blog, we will explain ” What is Unix FILE SYSTEM ” and basic details of file and directory in Linux. Everything in the UNIX System is a file. That is less of an oversimplification than you might think. When the first version of the system was being designed, before it even had a name, the discussions focused on the structure of a file system that would be clean and easy to use. The file system us central to the success and convenience of the UNIX system. It is one of the best examples of the “keep it simple” philosophy, showing the power achieved by the careful implementation of a few well-chosen ideas.
The Basic of file:
A file is a sequence of bytes. (A byte is a small chunk of information, typically 8 bit long. For our purposes, a byte is equivalent to a character). No structure is imposed on a file by the system, and no meaning is attached to its contents – the meaning of the bytes depends solely on the programs that interpret the file. Magnetic tapes, mail messages, characters types on the keyboard, line printer output, data flowing in pipes – each of these files is just a sequence of bytes as far as the system and the program in it are concerned. The best way to learn about files is to play with them, so start by creating a small file:
$ touch first-file.txt
What’s in a file?
The Format of a file is determined by the programs that use it; there is a wide variety of file types, perhaps because there is a wide variety of programs. But since file types are not determined by the file system, the kernel can’t tell you the type of a file.: it doesn’t know it. The file command makes an educated guess (we’ll explain how it how):
$file /bin /bin/ed /usr/src/cmd/ed.c /usr/man/man1/ed.1 /bin: directory /bin/ed: pure executable /bin/src/cmd/ed.c: C program text /usr/man/man1/ed.1: input text
These are four fairly typical files, all relate to the editor: the directory in which it resides (/bin), the “binary” or runnable program itself (/bin/ed), the “source” or C statements that define the program (/usr/src/cmd/ed.c) and the manual pages (/usr/man/man1/ed.1). To determine the types, the file didn’t pay attention to the names (although it could have), because naming conventions are just conventions, and thus not perfectly reliable.
Eg: files suffixed .c are almost always C source, but there is nothing to prevent you from creating .c file with arbitrary contents. Instead, the file reads the first few hundred bytes of a file and looks for cues to the file type.
Directories and filenames:
All the files you own have unambiguous names, starting with /usr/you, but if the only file you have is junk, and you type ls, it doesn’t print /usr/you/junk; the filename is printed without any prefix:
$ls Junk $
That is because each running program, that is, each process, has a current directory, and all filenames are implicitly assumed to start with the name of that directory unless they begin directly with a slash. Your login shell, and ls, therefore have a current directory. The command pwd (print working directory) identifies the current directory.
$pwd /usr/you $
The current directory is an attribute of the process, not a person or a program — people have login directories, processes have current directories.
End of this article, – What is Unix FILE SYSTEM.