Types of Files in Linux

In Linux/UNIX, ever thing is a file. Here devices, drivers etc., are treated as files.

The following are the types of files available in Linux / UNIX.

  • Regular (or) Ordinary (or) ASCII text files.
  • Directory files.
  • Device files

 Types of device files:

  • Character special files (all I/O devices)

          Ex: keyboard, mouse, monitor etc.,

  • Block special files ( All storage devices)

          Ex: cdrom, floppy, hard disk etc.,

 

  • Linked files

 Types of linked files:

  • Soft link file
  • Hard link file

 

  • Empty files
  • Socket files
  • Tar files
  • Binary executable files
  • Cpio files (copy archive file in and out)
  • Zip files

 

Knowing the file type:

There are many ways to figure out what type of file it is.

file command

Using "file" command we can find out if it’s a file or directory etc.

[admin@sys2 ~]$ file anaconda-ks.cfg
anaconda-ks.cfg: ASCII English text

 

ls command

By using ls –l (longlist format) command also we can determine the type of the file.

The starting letter of ls -l output, in each and every line indicates the type of the file.

[root@sys2 ~]# cd /sbin [root@sys2 sbin]# ls -l
total 15596
-rwxr-xr-x.  1 root root 10704   Jul 10   2012  accton
-rwxr-xr-x.  1 root root   8456   Jan 9    2013  addpart
-rwxr-xr-x.  1 root root  23952  Jan 9    2013  agetty
drwxr-xr-x.  1 root root  23952  Jan 9    2013  Sampdir
lrwxrwxrwx. 1 root root         7  Jan 22  01:30 clock ->hwclock

 

In the above outputs the first letter in each and every line indicates the type of the file

-   Regular file or ASCII text file
d  Directory file or device file
c  character special file
b  block special file
l   linked file
s  socket file

 

For Example:

crw-rw----. 1 root video 10, 175 Jan 29 12:45 agpgart
srw-rw-rw-. 1 root root 0 Jan 29 12:46 log
brw-rw----. 1 root disk 7, 3 Jan 29 12:45 loop3

  

Topics Summary