Files and folder management in Linux part 2 {File Types}


This article is all about Files and folder management in Linux part 2. In the previous post Files and folder management part 1 we learn about files and folder creation in Linux using different methods. Now in this tutorial, we will learn about types of files in Linux. There are various types of files will be present in the Linux operating system that is described by a single character in Linux. Each file type has a character and symbol by which we can easily identify what kind of file is it. In this tutorial, we will learn and try to understand the types of files in Linux and how to identify them. This is a common question to everyone who starts to learn Linux why is it much important to know file types. So here I give you answer this question that is because Linux considered everything as a file. When you start working on Linux you have to deal with different file types to effectively manage them. So let’s start here to learn file types in Linux.

First of all, we learn how many types of files present in the Linux?

By default, there are only three types of files present in the Linux that is given below

  1.  Regular Files

  2.  Directory Files

  3.  Special files: – In special files category there is 5 types of files are present

So in practical, we can say that there is 7 types of files will be present in the Linux.

Here I will provide you a list of file types with their associated character. Associated character is a symbol by which we can easily identify a file type in Linux. You can see the file type indication at the leftmost part of “ls -l” command in Linux.

• (-) Regular files

• (d) Directory files

• (b) Block files 

• (c) Character device files 

• (l) Symbolic link files

• (s) Socket link files also called a UNIX networking socket

• (p) Named pipe file or just a pipe file, first-in-first-out (FIFO) buffer

There is only one command you need to know which will help you to identify and categorize all the seven different file types found on the Linux system.

# ls -ld <file name>

Here is example output of the above command in Linux

# ls -ld rahul.txt
-rw-r--r-- 1 root root 26546 feb 24 2016 rahul.txt

ls command will show the file types as an encoded symbol found as the first character of the file permission part.

Now here we describe all the file types in detail.

how many types of files present on the linux

1.   Regular files (-)

Regular files are the most common file type which is found in the Linux system. Regular files rule all different files such as text files, shared libraries, images, and binary files and much more. You can create the regular file with the help of following command such as touch, cat, dd, vim, nano, gedit.

To saw a list of all Regular files use given below command on your Linux system.

[root@localhost ~]# ls -l | grep ^-
-rw------- 1 root root  1026 Feb  9 15:19 anaconda-ks.cfg
-rw-r--r-- 1 root root 29623 Feb  9 15:18 install.log
-rw-r--r-- 1 root root  3671 Feb  9 15:17 install.log.syslog
-rw-r--r-- 1 root root    50 Feb 25 03:01 rahul.txt

To remove regular files, you can use rm command. like here I remove the rahul.txt file from above result.

[root@localhost ~]# rm -rf rahul.txt

2. Directory files (d)

The directory is the second most common file type after the Regular files which is found in Linux system. A directory can be created with the help of mkdir command.

To saw a list of all Directory files use given below command on your Linux system

[root@localhost ~]# ls -l | grep ^d
drwxr-xr-x 3 root root  4096 Feb 24 23:39 Desktop
drwxr-xr-x 2 root root  4096 Feb 25 03:20 mohit
drwxr-xr-x 2 root root  4096 Feb 25 03:18 rahul
drwxr-xr-x 2 root root  4096 Feb 25 03:20 satish

To remove an empty directory use the rmdir command and if you will use the rmdir command to remove the directory which contains additional files, then there will get an error message. Like here I try to delete rahul directory which contains files in it. Now you saw that it shows error in deleting the directory. Now I try to delete satish which does not contain files in it. if you want to remove a directory which contains files in it then use rmdir -rf rahul then press enter to delete that directory permanently with files.

[root@localhost ~]# rmdir rahul
rmdir: rahul: Directory not empty
[root@localhost ~]# rmdir satish

3. Block files (b)

Block files are mainly hardware related files which find inside /dev/directory. To create a block file use fdisk command or virtual partition.

To saw a list of all Block files use given below command on your Linux system.

[root@localhost ~]# ls -l /dev/* |grep ^b
brw-r----- 1 root disk    7,    0 Feb 25 02:58 /dev/loop0
brw-r----- 1 root disk    7,    1 Feb 25 02:58 /dev/loop1
brw-r----- 1 root disk    7,    2 Feb 25 02:58 /dev/loop2
brw-r----- 1 root disk    7,    3 Feb 25 02:58 /dev/loop3
brw-r----- 1 root disk    7,    4 Feb 25 02:58 /dev/loop4
brw-r----- 1 root disk    7,    5 Feb 25 02:58 /dev/loop5
brw-r----- 1 root disk    7,    6 Feb 25 02:58 /dev/loop6
brw-r----- 1 root disk    7,    7 Feb 25 02:58 /dev/loop7
brw-r----- 1 root disk    9,    0 Feb 25 02:58 /dev/md0
brw-r----- 1 root disk    1,    0 Feb 25 02:57 /dev/ram0
brw-r----- 1 root disk    1,    1 Feb 25 02:57 /dev/ram1
brw-r----- 1 root disk    1,   10 Feb 25 02:57 /dev/ram10
brw-r----- 1 root disk    1,   11 Feb 25 02:57 /dev/ram11
brw-r----- 1 root disk    1,   12 Feb 25 02:57 /dev/ram12
brw-r----- 1 root disk    1,   13 Feb 25 02:57 /dev/ram13
brw-r----- 1 root disk    1,   14 Feb 25 02:57 /dev/ram14
brw-r----- 1 root disk    1,   15 Feb 25 02:57 /dev/ram15
brw-r----- 1 root disk    1,    2 Feb 25 02:57 /dev/ram2
brw-r----- 1 root disk    1,    3 Feb 25 02:57 /dev/ram3
brw-r----- 1 root disk    1,    4 Feb 25 02:57 /dev/ram4
brw-r----- 1 root disk    1,    5 Feb 25 02:57 /dev/ram5
brw-r----- 1 root disk    1,    6 Feb 25 02:57 /dev/ram6
brw-r----- 1 root disk    1,    7 Feb 25 02:57 /dev/ram7
brw-r----- 1 root disk    1,    8 Feb 25 02:57 /dev/ram8
brw-r----- 1 root disk    1,    9 Feb 25 02:57 /dev/ram9
brw------- 1 root root    8,    1 Feb 25 02:57 /dev/root
brw-rw---- 1 root disk   11,    0 Feb 25 02:58 /dev/scd0
brw-r----- 1 root disk    8,    0 Feb 25 02:57 /dev/sda
brw-r----- 1 root disk    8,    1 Feb 25 02:58 /dev/sda1
brw-r----- 1 root disk    8,    2 Feb 25 02:57 /dev/sda2
brw-r----- 1 root disk    8,    3 Feb 25 02:57 /dev/sda3
brw-r----- 1 root disk    8,    5 Feb 25 02:57 /dev/sda5
brw-r----- 1 root disk    8,    6 Feb 25 02:57 /dev/sda6
brw------- 1 root root 253,  0 Feb 25 02:58 vg00-lv1

4. Character device files (c)

Character devices are accessed through device files. Character and Block device files allow users and programs to communicate with hardware peripheral devices. Most devices in the world are a character.

To saw a list of all Character device files use given below commands on your Linux system

[root@localhost ~]# ls -l /dev/* |grep ^c
crw-rw---- 1 root audio  14,   12 Feb 25 02:58 /dev/adsp
crw------- 1 root root   10,  175 Feb 25 02:58 /dev/agpgart
crw-rw---- 1 root audio  14,    4 Feb 25 02:58 /dev/audio
crw------- 1 root root   10,   62 Feb 25 02:59 /dev/autofs
crw------- 1 root root    5,    1 Feb 25 02:58 /dev/console
crw-rw---- 1 root root   14,    9 Feb 25 02:58 /dev/dmmidi
crw-rw---- 1 root audio  14,    3 Feb 25 02:58 /dev/dsp
crw-rw-rw- 1 root root    1,    7 Feb 25 02:58 /dev/full
crw------- 1 root root   10,  228 Feb 25 02:58 /dev/hpet
crw------- 1 root root    1,   11 Feb 25 02:58 /dev/kmsg
crw-r----- 1 root kmem    1,    1 Feb 25 02:58 /dev/mem
crw-rw---- 1 root audio  14,    2 Feb 25 02:58 /dev/midi
crw-rw---- 1 root audio  14,    0 Feb 25 02:58 /dev/mixer
crw-rw-rw- 1 root root    1,    3 Feb 25 02:58 /dev/null
crw-rw---- 1 root root   10,  144 Feb 25 02:58 /dev/nvram
crw------- 1 root root    1,   12 Feb 25 02:58 /dev/oldmem
crw-rw---- 1 root lp     99,    0 Feb 25 02:58 /dev/parport0
crw-rw---- 1 root lp     99,    1 Feb 25 02:58 /dev/parport1
crw-rw---- 1 root lp     99,    2 Feb 25 02:58 /dev/parport2
crw-rw---- 1 root lp     99,    3 Feb 25 02:58 /dev/parport3
crw-r----- 1 root kmem    1,    4 Feb 25 02:58 /dev/port
crw------- 1 root root  108,    0 Feb 25 02:58 /dev/ppp
crw-rw-rw- 1 root tty     5,    2 Feb 25 03:57 /dev/ptmx
crw-rw-rw- 1 root root    1,    8 Feb 25 02:58 /dev/random
crw------- 1 root root  162,    0 Feb 25 02:58 /dev/rawctl
crw-r--r-- 1 root root   10,  135 Feb 25 02:57 /dev/rtc
crw-rw---- 1 root audio  14,    1 Feb 25 02:58 /dev/sequencer
crw-rw---- 1 root audio  14,    8 Feb 25 02:58 /dev/sequencer2
crw------- 1 root root   21,    0 Feb 25 02:58 /dev/sg0
crw------- 1 root root   21,    1 Feb 25 02:58 /dev/sg1
crw------- 1 root root   10,  231 Feb 25 02:58 /dev/snapshot
crw------- 1 root root    4,    0 Feb 25 02:57 /dev/systty
crw-rw-rw- 1 root tty     5,    0 Feb 25 02:58 /dev/tty
crw-rw---- 1 root root    4,    0 Feb 25 02:57 /dev/tty0
crw--w---- 1 root tty     4,    1 Feb 25 03:06 /dev/tty1
crw-rw---- 1 root tty     4,   10 Feb 25 02:57 /dev/tty10
crw-rw---- 1 root tty     4,   11 Feb 25 02:57 /dev/tty11
crw-rw---- 1 root tty     4,   12 Feb 25 02:57 /dev/tty12
crw-rw---- 1 root tty     4,   13 Feb 25 02:58 /dev/tty13
crw-rw---- 1 root tty     4,   14 Feb 25 02:58 /dev/tty14
crw-rw---- 1 root tty     4,   15 Feb 25 02:58 /dev/tty15
crw-rw---- 1 root tty     4,   16 Feb 25 02:58 /dev/tty16
crw-rw---- 1 root tty     4,   17 Feb 25 02:58 /dev/tty17
crw-rw---- 1 root tty     4,   18 Feb 25 02:58 /dev/tty18
crw-rw---- 1 root tty     4,   19 Feb 25 02:58 /dev/tty19
crw------- 1 root root    4,    2 Feb 25 02:59 /dev/tty2
crw-rw---- 1 root tty     4,   20 Feb 25 02:58 /dev/tty20
crw-rw---- 1 root tty     4,   21 Feb 25 02:58 /dev/tty21
crw-rw---- 1 root tty     4,   22 Feb 25 02:58 /dev/tty22
crw-rw---- 1 root tty     4,   23 Feb 25 02:58 /dev/tty23
crw-rw---- 1 root tty     4,   24 Feb 25 02:58 /dev/tty24
crw-rw---- 1 root tty     4,   25 Feb 25 02:58 /dev/tty25
crw-rw---- 1 root tty     4,   26 Feb 25 02:58 /dev/tty26
crw-rw---- 1 root tty     4,   27 Feb 25 02:58 /dev/tty27
crw-rw---- 1 root tty     4,   28 Feb 25 02:58 /dev/tty28
crw-rw---- 1 root tty     4,   29 Feb 25 02:58 /dev/tty29
crw------- 1 root root    4,    3 Feb 25 02:59 /dev/tty3
crw-rw---- 1 root tty     4,   30 Feb 25 02:58 /dev/tty30
crw-rw---- 1 root tty     4,   31 Feb 25 02:58 /dev/tty31
crw-rw---- 1 root tty     4,   32 Feb 25 02:58 /dev/tty32
crw-rw---- 1 root tty     4,   33 Feb 25 02:58 /dev/tty33
crw-rw---- 1 root tty     4,   34 Feb 25 02:58 /dev/tty34
crw-rw---- 1 root tty     4,   35 Feb 25 02:58 /dev/tty35
crw-rw---- 1 root tty     4,   36 Feb 25 02:58 /dev/tty36
crw-rw---- 1 root tty     4,   37 Feb 25 02:58 /dev/tty37
crw-rw---- 1 root tty     4,   38 Feb 25 02:58 /dev/tty38
crw-rw---- 1 root tty     4,   39 Feb 25 02:58 /dev/tty39
crw------- 1 root root    4,    4 Feb 25 02:59 /dev/tty4
crw-rw---- 1 root tty     4,   40 Feb 25 02:58 /dev/tty40
crw-rw---- 1 root tty     4,   41 Feb 25 02:58 /dev/tty41
crw-rw---- 1 root tty     4,   42 Feb 25 02:58 /dev/tty42
crw-rw---- 1 root tty     4,   43 Feb 25 02:58 /dev/tty43
crw-rw---- 1 root tty     4,   44 Feb 25 02:58 /dev/tty44
crw-rw---- 1 root tty     4,   45 Feb 25 02:58 /dev/tty45
crw-rw---- 1 root tty     4,   46 Feb 25 02:58 /dev/tty46
crw-rw---- 1 root tty     4,   47 Feb 25 02:58 /dev/tty47
crw-rw---- 1 root tty     4,   48 Feb 25 02:58 /dev/tty48
crw-rw---- 1 root tty     4,   49 Feb 25 02:58 /dev/tty49
crw------- 1 root root    4,    5 Feb 25 02:59 /dev/tty5
crw-rw---- 1 root tty     4,   50 Feb 25 02:58 /dev/tty50
crw-rw---- 1 root tty     4,   51 Feb 25 02:58 /dev/tty51
crw-rw---- 1 root tty     4,   52 Feb 25 02:58 /dev/tty52
crw-rw---- 1 root tty     4,   53 Feb 25 02:58 /dev/tty53
crw-rw---- 1 root tty     4,   54 Feb 25 02:58 /dev/tty54
crw-rw---- 1 root tty     4,   55 Feb 25 02:58 /dev/tty55
crw-rw---- 1 root tty     4,   56 Feb 25 02:58 /dev/tty56
crw-rw---- 1 root tty     4,   57 Feb 25 02:58 /dev/tty57
crw-rw---- 1 root tty     4,   58 Feb 25 02:58 /dev/tty58
crw-rw---- 1 root tty     4,   59 Feb 25 02:58 /dev/tty59
crw------- 1 root root    4,    6 Feb 25 02:59 /dev/tty6
crw-rw---- 1 root tty     4,   60 Feb 25 02:58 /dev/tty60
crw------- 1 root root 13, 66 Feb 25 02:58 event2
crw------- 1 root root 13, 67 Feb 25 02:58 event3
crw------- 1 root root 13, 63 Feb 25 02:58 mice
crw------- 1 root root 13, 32 Feb 25 02:58 mouse0
crw------- 1 root root 13, 33 Feb 25 02:58 mouse1
crw------- 1 root root  10, 63 Feb 25 02:58 control
crw------- 1 root root 10, 200 Feb 25 02:58 tun
crw--w---- 1 root tty 136, 1 Feb 25 03:57 1
crw-rw---- 1 root audio 116, 8 Feb 25 02:58 controlC0
crw-rw---- 1 root audio 116, 4 Feb 25 02:58 midiC0D0
crw-rw---- 1 root audio 116, 7 Feb 25 02:58 pcmC0D0c
crw-rw---- 1 root audio 116, 6 Feb 25 02:58 pcmC0D0p
crw-rw---- 1 root audio 116, 5 Feb 25 02:58 pcmC0D1p
crw-rw---- 1 root audio 116, 3 Feb 25 02:58 seq
crw-rw---- 1 root audio 116, 2 Feb 25 02:58 timer

5. Symbolic Link files (l)

These are linked files to other files. They are either Directory/regular files.There are two types of link files available in Linux Soft and Hard. With symbolic links, an administrator can assign a file or directory multiple identities. A soft link is also known as symbolic links.

lrwxrwxrwx 1 root root 3 Feb 25 04:20 deepit -> dipsa 
lrwxrwxrwx 1 root root 0 Feb 25 04:33 jaya -> hemendra

6. Named pipe files (p)

Named pipe files refers to the property that the order of bytes going in is the same coming out. Named pipe files allows you to communicate between two local processes.

To create a named pipe file use given below command on your Linux system

[root@localhost ~]# mkfifo satish

To saw a list of all Named pipe files use given below command on your Linux system

[root@localhost ~]# ls -l |grep ^p
prw-r--r-- 1 root root     0 Feb 25 04:34 davi
prw-r--r-- 1 root root     0 Feb 25 04:33 jaya
prw-r--r-- 1 root root     0 Feb 25 04:34 manu
prw-r--r-- 1 root root     0 Feb 25 04:34 satish
prw-r--r-- 1 root root     0 Feb 25 04:34 technohelper24

7.  Socket files (s)

Socket files are used to made communication possible between applications. In other words, we can say that socket file is used to pass information between applications for communication purpose.

To saw a list of all the socket files use given below command

[root@localhost ~]# ls -l |grep ^s
srw-rw-rw- 1 root root 0 feb 25 04:35 /dev/log
srwxrwxrsx 1 root root 0 feb 25 04:36 /var/run/cups.sock

THAT’S IT

These are the various types of files which are present in the Linux operating system. If you have queries and suggestions feel free to ask and suggest through the comment section and also provide feedback to us because your feedback is valuable for us.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s