Linux Command - Linux file types

There are different file types in Linux file system.

File Types

use ls -l command to check file types. the file type is encoded, “-“ is for “regular file”.

The complete list of file types

  • - : regular file
  • d : directory
  • c : character device file
  • b : block device file
  • s : local socket file
  • p : named pipe
  • l : symbolic link

Regular files

Regular file is the most common file type in Linux file system.

1
ls -l /etc/hosts

output - this is a regular file!

1
-rw-r--r-- 1 root root 239 Dec  7 20:34 /etc/hosts

Directory

Directory is also very common

Demo

1
2
3
cd /tmp
mkdir dir
ls -l /tmp

output

1
drwxr-xr-x 2 root root 4096 Dec 24 12:42  dir

Character Device

Users and programs communicate with hardware using character and block device

1
ls -l /dev/usb

output

1
2
3
4
total 0
crw------- 1 root root 180, 0 Dec 24 09:57 hiddev0
crw------- 1 root root 180, 1 Dec 24 09:57 hiddev1
crw------- 1 root root 180, 2 Dec 24 09:57 hiddev2

Block Device

Similar to Character Device, common block devices are hard drives, memory.

1
ls -l /dev/sda

output

1
brw-rw---- 1 root disk 8, 0 Dec 24 09:57 /dev/sda

Local Socket

you can find socker file in /var/run directory.

1
2
3
cd 
cd /var/run/systemd/journal
ls -l

output

1
2
3
4
5
6
7
8
total 4
srw-rw-rw- 1 root root 0 Dec 25 11:41 dev-log
-rw-r--r-- 1 root root 0 Dec 25 11:41 flushed
-rw-r--r-- 1 root root 8 Dec 25 11:41 kernel-seqnum
srw-rw-rw- 1 root root 0 Dec 25 11:41 socket
srw-rw-rw- 1 root root 0 Dec 25 11:41 stdout
drwxr-xr-x 2 root root 3320 Dec 25 16:05 streams
srw-rw-rw- 1 root root 0 Dec 25 11:41 syslog

Named Pipe

named pipes allow communication between two local processes.

create named pipe

1
mkfifo pipe

ls -l output

1
prw-r--r-- 1 xing xing    0 Dec 24 13:53  pipe

create symbolic link

1
ln -s file1 file1.link

ls -l output

1
2
-rw-r--r-- 1 xing xing    0 Dec 24 13:54  file1
lrwxrwxrwx 1 xing xing 5 Dec 24 13:54 file1.link -> file1

Reference