You know in Linux file is everything. In this tutorial i will explain you one of the most and important pillar which support Linux and UNIX– the File System. Known as Linux file system in general.
The file system in Linux is one of its simple and conceptually clean feature. As you know Linux looks at everything as a file and a Linux system has thousands of files resides in it.
What is a File ?
A container which stores information is known as File. You can treat it simply as a sequence of characters. It can be a document, picture, audio or video stream, data library, program file, application, or other collection of data.
Very important point here, Linux treats directories and devices as a file. In Linux system a directory is a folder which keeps filenames and other sub-directories. A Linux system considers all physical devices like your hard drive, CD-ROM, printer, memory etc. as files.
Imp: In Linux system a shell is also a file and kernel too.
Linux File Types
In UNIX there are different types of categories are there.
- Ordinary File or Regular File
- Directory File
- Device File
- Symbolic link file or soft link file
- FIFO (Named Pipe)
An ordinary file also known as regular file commonly is the most common file type in Linux system. All programs (C, C+, Java etc.) belongs to this file type.
Ordinary file is divided into two types such as Text File and Binary File.
Text File:: It contains only printable ASCSI character within the range 0-127. Often we can view the content of a text file and can make sense out of it. Here every line ends with a new line character, created by ENTER Key.
For Example: ALl ‘C’, Source Codes, all Python Scripts, Shell Scripts
Binary File:: It contains both printable as well as non-printable characters within the ASCSI range 0-255. We can not make any sense after viewing a binary file because it contains ASCSI symbols.
For Example: All C and Java Object codes, all image, video, audio files are binaries. And also most Linux/UNIX commands are Binary File type.
When displaying the Binary File type with cat command it produces unreadable output and it may also disturb your terminal settings.
Very important point you should keep in your mind that some users say and sometimes it is commonly said that a directory contains files and other directories. But it contains their names and inode number of a file or directory.
If you have directory and 10 files in a directory, there will be only 10 entries resides in the directory. It contains 2 attributes of a file.
- The File name
- Inode Number( A unique identification number of every newly created file which system assigns)
Unlike windows folders Linux directories never contain file data, file data are stored in data blocks.
Tip: A directory contains filename and not the file’s contents.
Linux or UNIX considers every hardware devices as a file. They have different types of names also. All these device files are stored in the directory (/dev). A device file is indeed special it’s not really a stream of characters. In fact it does not contain anything at all.
Symbolic link File
Symbolic link file also known as Soft link file. It is a very special type of file which contains path of the original file. Also you can say a symbolic link is a reference to another file.
FIFO (Named Pipe)
One of the main advantage and strength of Linux or Unix it has always been inter-process communication. Among the facilities provided by the OS are pipes, which connect the output of one process to the input of another. This is fine if both processes exist in the same parent process space, started by the same user, but there are circumstances where the communicating processes must use FIFOs, here referred to as named pipes. One such circumstance occurs when the processes must be executed under different user names and permissions.
Named pipes are special files that can exist anywhere in the file system. They can be created with the command
A Unix/Linux socket is a special file which allows for advanced inter-process communication. A Unix Socket is used in a client-server application framework. In essence, it is a stream of data, very similar to network stream (and network sockets), but all the transactions are local to the filesystem. Unlike named pipes which allow only unidirectional data flow, sockets are fully duplex-capable.
Door ( Not a Linux File type But a UNIX file type)
A door is a special file for inter-process communication between a client and server, currently implemented only in Solaris. It does not come under Linux file types.
A door is marked with a
D (upper case) as the first letter of the mode string.
Parent Child Relationship
All the files in Linux system are related to each other. The collection of all these files (Ordinary, directory, device etc.) is called as file system. And the filesystem in Linux is organized in a hierarchical structure. Directories/Files are here in a parent child relationship.
Linux file system is considered as single monolithic tree, an inverted one, root upwards.
As you can see this tree is organized in hierarchical structure.
See what are the directories and what it contains.
|Path||Type of Data Holds|
|/bin||Stands for binary. It contains command files of maximum commands|
|/dev||It contains all device files|
|/etc||This directory contains system configuration.|
|/home||Home directory contain all users|
|/lib||This directory contains all C language library files|
|/sbin||Super user bin. This dir contains command files of administrative commands|
|/stand/unix||this is unix kernel|
|/boot/vmlinuz||Path of Linux kernel path|
|/tmp||It contains temporary files, system wipes away this files in regular interval|
|/usr or /usr/bin||this directory contains command files of few additional commands|
|/usr/include||This dir. contain all C language header files|
|/var||This is variable part of the file system. Contains all user mailbox, crontab file of all user|
|/var/log||Contains system logs|
Path of A file
A file path is the human-readable representation of a file or directory location on a computer system. In Linux system the Path of a File is of two types.
- Absolute Path
- Relative Path
Absolute Path : This is the path with respect to ‘/’ directory.
For Example: If you are on your dir1 directory and wanted to jump to X1 file, the command for Absolute path will be as below
Relative Path : This is the path with respect to current directory. Relative pathing is quite helpful while accessing files and directory down the hierarchy. But while going above the hierarchy or jumping to a different branch we need absolute path.
For example: If you are dir1 and wanted to jump to X1
Remember POSIX recommends file types and Linux is POSIX complaint. But Solaris have an extra file type i.e Door which i have mentioned anyways. Other-than that whatever file types are discussed are part of Linux file type. But it does not come under Linux file type. Though i have mentioned major discussion of Linux file types, in this post but i have covered all the file in UNIX and Linux.