In Linux systems everything is considered as a file. In this post I will explain about different Linux file types. It includes regular files, directories, links, character special file,socket,named pipes and block device.
Different Linux File Types
|c||Character special file|
Regular file (-)
They are normal data for example text files, executable files, images, compressed files and so on.
[email protected]:~$ ls -l | grep ^-
-rw-r–r– 1 admin admin 183 May 5 19:32 test.py
-rw-r–r– 1 admin admin 337 May 5 19:32 user.sh
Directory Files (d)
They contains regular files/folders/special files stored on a physical device. It is also called a file. Its actual purpose is to make sure that there is a good structure maintained on the system.
[email protected]:~$ ls -l | grep ^d
drwxrwxr-x 2 admin admin 4096 May 5 19:41 Desktop
drwxrwxr-x 2 admin admin 4096 May 5 20:10 test
are those files that contains a reference to another file or directory in the form of an absolute or relative path. There are two types of link files available in Linux i.e soft and hard link. Links can be created using ln command.
[email protected]:~$ ls -l /proc/ | grep ^l
lrwxrwxrwx 1 root root 11 May 5 22:28 mounts -> self/mounts
lrwxrwxrwx 1 root root 8 May 5 22:28 net -> self/net
lrwxrwxrwx 1 root root 0 May 6 2016 self -> 3092
They allows access to various devices in your Linux system. Every device in Linux has a special file associated with it based on how Linux interacts with different devices. Examples: Virtual terminals, terminals and serial modems etc
Character special files (c)
When a character special file is used for device I/O, data is transferred one character at a time (1 byte at a time). This type of access is called raw device access.
crw–w—- 1 root tty 4, 0 May 5 22:17 tty0
crw-rw—- 1 root tty 4, 1 May 5 22:17 tty1
Block device files (d)
When a block special file is used for device I/O, data is transferred in large fixed-size blocks( 1 block = 512 bytes to 32KB). This type of access is called block device access. Examples: Hard disk, DVD and CD etc
drwxr-xr-x 2 root root 60 May 6 2016 cpu
drwxr-xr-x 4 root root 80 May 6 2016 disk
Sockets are used for interprocess communication i.e pass information between applications for communication purpose.
[email protected]:~$ ls -al /dev/log
srw-rw-rw- 1 root root 0 May 5 22:17 /dev/log
Named Pipe (p)
Pipes are also used for interprocess communication. They are also called as FIFO [First In, First Out] which refers to the property that the order of bytes going in is the same coming out. Their purpose is to connect I/O of two Unix processes accessing the pipe. Pipes can be created using mkfifo command.
[email protected]:~$ ls -al /dev/xconsole
prw-r—– 1 root admin 0 May 5 22:22 /dev/xconsole
That’s it. Hope it gives a better idea about the different Linux file types.