What are the different file types in linux

"In a UNIX system, everything is a file; if something is not a file, it is a process." - Unix Philosophy

The above quote  is one of the philosophies Linux has inherited from Unix. i.e.  in Linux everything is a file, be it a regular text file, directory or a hardware component like hard disk. In Linux, files are classified in to 7 types. They are
  1. Regular Files
  2. Directory
  3. Block Files
  4. Character Files
  5. Symbolic Link Files
  6. Socket Files
  7. Named Pipe Files

Before  going in to the details of each file type, lets see how to determine the file type with ls -l command output. Consider the below example

In the above example ls -l displays the long list details of a file README.txt. The first field of the output (highlighted by red circle), known as the mode string, represents the file type. In this example the first field is a - (dash) symbol, which means the file is a regular file. As the file type changes first field will change accordingly. Now lets analyze each file type


Regular Files (-)

These are the ordinary files. Some example for ordinary files are .txt, .csv, .pdf, .zip,  .jpeg, .avi and so on. The first field of ls -l output of a regular file is - (dash) symbol . Displayed below is  the ls -l output of a regular file named README.txt

ls -l README.txt
 -rw-r--r--. 1 calypso calypso 4244 Sep 26  2011 README.txt

Directory (d)

In linux directories are just another file which may or may not contain the names of  other files and directories. In the case of directories the first field of the ls -l output will be 'd'.














In the above examples both Downloads and Misc are directories and if you see the file type part of both Downloads and Misc you can see a 'd' which means both are directories.

Block Files (b)

These are special files or device files. A block file is a hardware file which read/write data in blocks. Hard Disks, CD_ROMS etc.. are som examples for block devices and there corresponding files can be located under /dev director. In the case of block files the file type will be repersented by 'b'. For example a SCSI/SATA Hard Disk file under linux will be something similar to /dev/sda. The ls -l output of /dev/sda will be


Character File (c)

Character special files or character devices reads and write data one character at a time. Character files are mainly used for stream communication and the devices associated with character files are mainly keyboard, mice, serial modems, virtual terminal and so on. The file type portion of ls -l output of a character file is represented by 'c'. Given below is the ls -l output of a keyboard event file, /dev/input/event0

 

Symbolic Link File (l)

Symbolic links or soft links are files which contains a reference to another file or directory. i.e. these files point towards a target file or directory. This is something similar to a shortcut file in Windows  operating system. The file type portion of ls -l output of a character file is represented by 'l'. Lets see the ls -l output of /bin/java file
 









In the above example you can see the first field of ls -l output of /bin java is 'l'. That means the file is a Symbolic link. If you see the final part of the output you can see /bin/java is ponted towards another file /etc/alternatives/java. i.e. the file /etc/alternatives/java is the target file for /bin/java. If you again looking at the ls -l output for /etc/alternatives/java, you can this file also is a symbolic link and is pointed towards a regular file /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.60-2.4.3.0.fc19.i386/jre/bin/java. So in the above example we can say that /bin/java is ultimately pointed to an executable file java located in /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.60-2.4.3.0.fc19.i386/jre/bin/ directory

Socket Files (s)

Sockets are special files used for inter-process communication, i.e communication between multiple process. Sockets are created when a process is started and terminated when the process stops. For a socket file the mode strings is 's'. Consider we have mysql database running in our system and the ls -l output of the socket file will look similar to the one given below






Named Pipe Files (p)

A Named Pipe or FIFO(First In First Out) is also a method used for inter-process communication. In unix/*nix we use objects called pipes, represented by '|', to redirect or feed output of one process as in put to another process. But the traditional pipes are temporary. They exist as long as the process exists. Also both process has to be started by the same user. But there are cases when the processes have to be executed under different user names and permissions. During these circumstances we use named pipes. For a named pipe file the mode strings is 'p'. The ls -l ouput of a named file will look like the one given below








These are are the different file type that we come across in a linux system. Apart from using ls- l command we can determine the file type with find command

Comments

Popular posts from this blog

Understanding awk command with examples

Understanding sed command with example -Part 1

How to install a Software in Linux