In this tutorial we will learn and try to understand the types of files in Linux and how to identify them all.Before using any operating system we must know about the types of files available in those operating system.Like other OS Linux OS also has some files and each files have different properties and assigned for different task.
Types of files in linux.
The following are the list of file types, and their associated character:
• – regular file
• d directory
• b block device
• c character device
• l symbolic link
• s socket link, also called a Unix networking socket
• p first-in first-out (FIFO) buffer, also called a named pipe
1.Regular Files(-)
Regular files are normal files created by users.
How to create Regular Files.
There are so many ways to create a regular files in linux.
touch ,cat,dd,vim,vi,nano,gedit etc
#ls -l |grep ^-
[root@localhost ~]# ls -l|grep ^- -rw------- 1 root root 991 Sep 29 18:01 anaconda-ks.cfg -rw-r--r-- 1 root root 159 Oct 16 03:09 hackinginjaipur -rw-r--r-- 1 root root 29623 Sep 29 18:01 install.log -rw-r--r-- 1 root root 3661 Sep 29 18:01 install.log.syslog -rw-r--r-- 1 root root 3005818880 Sep 30 14:16 rhel54iso.iso [root@localhost ~]#
2.Directory files(d)
#ls -l |grep ^d
[root@localhost ~]# ls -l|grep ^d drwxr-xr-x 3 root root 4096 Jan 9 06:30 Desktop drwxr-xr-x 2 root root 4096 Nov 4 00:49 E drwxrwxr-x+ 2 tiwary root 4096 Nov 3 00:32 test drwxr-xr-x 2 root root 4096 Jan 9 01:46 testing.txt [root@localhost ~]#
3.Block Files (b)
Block Files are mainly hardware related files usually find inside /dev/ directory
#ls -l /dev/* |grep ^b
[root@localhost ~]# ls -l /dev/* |grep ^b brw-rw---- 1 root disk 22, 0 Feb 20 22:35 /dev/hdc brw-r----- 1 root disk 7, 0 Feb 20 22:35 /dev/loop0 brw-r----- 1 root disk 7, 1 Feb 20 22:35 /dev/loop1 brw-r----- 1 root disk 7, 2 Feb 20 22:35 /dev/loop2 brw-r----- 1 root disk 7, 3 Feb 20 22:35 /dev/loop3 brw-r----- 1 root disk 7, 4 Feb 20 22:35 /dev/loop4 brw-r----- 1 root disk 7, 5 Feb 20 22:35 /dev/loop5 brw-r----- 1 root disk 7, 6 Feb 20 22:35 /dev/loop6 brw-r----- 1 root disk 7, 7 Feb 20 22:35 /dev/loop7 brw-r----- 1 root disk 9, 0 Feb 20 22:35 /dev/md0 brw-r----- 1 root disk 1, 0 Feb 20 22:34 /dev/ram0 brw-r----- 1 root disk 1, 1 Feb 20 22:34 /dev/ram1 brw-r----- 1 root disk 1, 10 Feb 20 22:34 /dev/ram10 brw-r----- 1 root disk 1, 11 Feb 20 22:34 /dev/ram11 brw-r----- 1 root disk 1, 12 Feb 20 22:34 /dev/ram12 brw-r----- 1 root disk 1, 13 Feb 20 22:34 /dev/ram13 brw-r----- 1 root disk 1, 14 Feb 20 22:34 /dev/ram14 brw-r----- 1 root disk 1, 15 Feb 20 22:34 /dev/ram15 brw-r----- 1 root disk 1, 2 Feb 20 22:34 /dev/ram2 brw-r----- 1 root disk 1, 3 Feb 20 22:34 /dev/ram3 brw-r----- 1 root disk 1, 4 Feb 20 22:34 /dev/ram4 brw-r----- 1 root disk 1, 5 Feb 20 22:34 /dev/ram5 brw-r----- 1 root disk 1, 6 Feb 20 22:34 /dev/ram6 brw-r----- 1 root disk 1, 7 Feb 20 22:34 /dev/ram7 brw-r----- 1 root disk 1, 8 Feb 20 22:34 /dev/ram8 brw-r----- 1 root disk 1, 9 Feb 20 22:34 /dev/ram9 brw------- 1 root root 8, 1 Feb 20 22:35 /dev/root brw-r----- 1 root disk 8, 0 Feb 20 22:35 /dev/sda brw-r----- 1 root disk 8, 1 Feb 20 22:35 /dev/sda1 brw-r----- 1 root disk 8, 2 Feb 20 22:35 /dev/sda2 brw-r----- 1 root disk 8, 4 Feb 20 22:35 /dev/sda4 brw-r----- 1 root disk 8, 5 Feb 20 22:35 /dev/sda5 brw-r----- 1 root disk 8, 6 Feb 20 22:35 /dev/sda6 brw-r----- 1 root disk 8, 7 Feb 20 22:35 /dev/sda7 brw------- 1 root root 253, 0 Feb 20 22:35 vg00-lv1 [root@localhost ~]#
4.character device files(c)
character devices are accessed through device files.
As we all know devices are divided in to two types: block devices and character devices.Most devices in the world are character.
#ls -l /dev/* |grep ^c
crw-rw---- 1 root tty 4, 47 Feb 20 22:35 /dev/tty47 crw-rw---- 1 root tty 4, 48 Feb 20 22:35 /dev/tty48 crw-rw---- 1 root tty 4, 49 Feb 20 22:35 /dev/tty49 crw------- 1 root root 4, 5 Feb 20 22:37 /dev/tty5 crw-rw---- 1 root tty 4, 50 Feb 20 22:35 /dev/tty50 crw-rw---- 1 root tty 4, 51 Feb 20 22:35 /dev/tty51 crw-rw---- 1 root tty 4, 52 Feb 20 22:35 /dev/tty52 crw-rw---- 1 root tty 4, 53 Feb 20 22:35 /dev/tty53 crw-rw---- 1 root tty 4, 54 Feb 20 22:35 /dev/tty54 crw-rw---- 1 root tty 4, 55 Feb 20 22:35 /dev/tty55 crw-rw---- 1 root tty 4, 56 Feb 20 22:35 /dev/tty56 crw-rw---- 1 root tty 4, 57 Feb 20 22:35 /dev/tty57 crw-rw---- 1 root tty 4, 58 Feb 20 22:35 /dev/tty58 crw-rw---- 1 root tty 4, 59 Feb 20 22:35 /dev/tty59 crw------- 1 root root 4, 6 Feb 20 22:37 /dev/tty6 crw-rw---- 1 root tty 4, 60 Feb 20 22:35 /dev/tty60 crw-rw---- 1 root tty 4, 61 Feb 20 22:35 /dev/tty61 crw-rw---- 1 root tty 4, 62 Feb 20 22:35 /dev/tty62 crw-rw---- 1 root tty 4, 63 Feb 20 22:35 /dev/tty63 crw-rw---- 1 root root 4, 7 Feb 20 22:34 /dev/tty7 crw-rw---- 1 root tty 4, 8 Feb 20 22:35 /dev/tty8 crw-rw---- 1 root tty 4, 9 Feb 20 22:34 /dev/tty9 crw-rw---- 1 root uucp 4, 64 Feb 20 22:34 /dev/ttyS0 crw-rw---- 1 root uucp 4, 65 Feb 20 22:34 /dev/ttyS1 crw-rw---- 1 root uucp 4, 66 Feb 20 22:34 /dev/ttyS2 crw-rw---- 1 root uucp 4, 67 Feb 20 22:34 /dev/ttyS3 cr--r--r-- 1 root root 1, 9 Feb 20 22:35 /dev/urandom crw------- 1 root root 442, 0 Feb 20 22:35 /dev/usbdev1.1_ep00 crw------- 1 root root 442, 0 Feb 20 22:35 /dev/usbdev1.1_ep81 crw------- 1 vcsa tty 7, 0 Feb 20 22:35 /dev/vcs crw------- 1 vcsa tty 7, 1 Feb 20 22:37 /dev/vcs1 crw------- 1 vcsa tty 7, 2 Feb 20 22:37 /dev/vcs2 crw------- 1 vcsa tty 7, 3 Feb 20 22:37 /dev/vcs3 crw------- 1 vcsa tty 7, 4 Feb 20 22:37 /dev/vcs4 crw------- 1 vcsa tty 7, 5 Feb 20 22:37 /dev/vcs5 crw------- 1 vcsa tty 7, 6 Feb 20 22:37 /dev/vcs6 crw------- 1 vcsa tty 7, 7 Feb 20 22:37 /dev/vcs7 crw------- 1 vcsa tty 7, 128 Feb 20 22:35 /dev/vcsa crw------- 1 vcsa tty 7, 129 Feb 20 22:37 /dev/vcsa1 crw------- 1 vcsa tty 7, 130 Feb 20 22:37 /dev/vcsa2 crw------- 1 vcsa tty 7, 131 Feb 20 22:37 /dev/vcsa3 crw------- 1 vcsa tty 7, 132 Feb 20 22:37 /dev/vcsa4 crw------- 1 vcsa tty 7, 133 Feb 20 22:37 /dev/vcsa5 crw------- 1 vcsa tty 7, 134 Feb 20 22:37 /dev/vcsa6 crw------- 1 vcsa tty 7, 135 Feb 20 22:37 /dev/vcsa7 crw-rw-rw- 1 root root 1, 5 Feb 20 22:35 /dev/zero crw------- 1 root root 13, 64 Feb 20 22:35 event0 crw------- 1 root root 13, 65 Feb 20 22:35 event1 crw------- 1 root root 13, 66 Feb 20 22:35 event2 crw------- 1 root root 13, 63 Feb 20 22:35 mice crw------- 1 root root 13, 32 Feb 20 22:35 mouse0 crw------- 1 root root 10, 63 Feb 20 22:35 control crw------- 1 root root 10, 200 Feb 20 22:35 tun crw--w---- 1 root tty 136, 1 Feb 20 22:59 1 crw-rw---- 1 root audio 116, 7 Feb 20 22:35 controlC0 crw-rw---- 1 root audio 116, 6 Feb 20 22:35 pcmC0D0c crw-rw---- 1 root audio 116, 5 Feb 20 22:35 pcmC0D0p crw-rw---- 1 root audio 116, 4 Feb 20 22:35 pcmC0D1c crw-rw---- 1 root audio 116, 3 Feb 20 22:35 seq crw-rw---- 1 root audio 116, 2 Feb 20 22:35 timer [root@localhost ~]#
5.named pipe files.(p)
Create pipe file using below command.
#mkfifo tiwary
#ls -l |grep ^p
[root@localhost ~]# mkfifo tiwary [root@localhost ~]# ls -l |grep ^p prw-r--r-- 1 root root 0 Feb 20 23:00 tiwary [root@localhost ~]#
6.symbolic linked file(l)
These are mainly linked files with other files.
It can be soft link or hard link.
soft link is also known as symbolic link.
#ls -l |grep ^l
[root@localhost ~]# ls -l |grep ^l lrwxrwxrwx 1 root root 1 Feb 20 23:01 linuxtiwary -> s [root@localhost ~]#
7.Socket Files (s)
Socket Files are used to made communication possible between applications.
#ls -l |grep ^s
Now I will explain all theses step by step and we understand each file type with examples.