Pages

Tuesday, July 17, 2012

Linux File Types

A File is a collection of data stored on the disk. It may be a device which reads data or writes data. Everything in linux is a file. There are various types of files available in linux. In this article we will see the types of files available in linux .These files can be identified by the ls -l command which displays the type of the file in the first alphabetic letter of the file system permissions field. A normal file is indicated by a dash ('-').

Normally when we type ls -l , the available files are displayed like ,

-rw-r--r-- 1 root root  0 Jul 25 19:20 sampl
prw-r--r-- 1 root root  0 Jul 27 14:03 pipe

The first character indicates the file type.The file type may be any one from these

    *  - denotes a regular file
    *  d denotes a directory
    *  b denotes a block special file
    *  c denotes a character special file
    *  l denotes a symbolic link
    *  p denotes a named pipe
    *  s denotes a socket


Regular file are normal files that we use normally in our daily operations. The first character for this will be '-'.

Directories are most common special file available. The first character for this will be 'D'.

Symbolic link is a reference to another file. This is stored as a representation of a referenced file path. The first character for this will be 'l'.

Named pipe : Linux provide support in the inter-process communication. This can be done by using Named pipes. These pipes normally connect the output of one process as input to another process. These named pipes are special files that can exist anywhere in the file system. These named pipe special files are made with the command mkfifo.The first character for this will be 'p'.

Socket Files are another special files helping the inter-process communication. This allows communication between 2 process. The first character for this will be 's'.

srw-rw-rw-   1 root  root        0 Jul 27 12:39 acpid.socket
srw-r-----     1 root  root        0 Jul 27 12:39 audispd_events
srwxrwxrwx  1 root  root        0 Jul 27 12:39 pcscd.comm


Device Files: Under linux each and every hardware device is treated as a file. a device file allows users to access hardware devices so that the users do not need to get into the details of the hardware. There are 2 types of device files available,

Character Files: These files talk to the device character by character.   Ex : terminal
Block Special Files: These files talk to the device block by block.        Ex : hard disk

A character file contains the first letter as 'c' and block files contain 'b' as first letter.

ls -l /dev/console
ls -l /dev/sda1

Happy learning, More to Come J