Soft Vs Hard link
2 min readFeb 3, 2021
Soft links:
As shown in the diagram soft links or symbolic links simply points to another file. It only contains the pathname of the file to which it is pointing.
Example:
# touch file1
# ln -s file1 link1
# ls -l
-rw-r--r-- 1 root root 0 Sep 19 14:41 link1
lrwxrwxrwx 1 root root 5 Sep 19 15:41 link1 -> file1
Hard links:
Every file uses atleast one hard link. So when you create a new file a new directory entry is created which is called link count. So when you create a new hard link to this file the link count increaments by 1.
Example:
# touch file1
# ls -l
-rw-r--r-- 1 root root 0 Sep 23 13:19 file1
# ln file1 file2
# ls -l
-rw-r--r-- 2 root root 0 Sep 23 13:19 file1
-rw-r--r-- 2 root root 0 Sep 23 13:19 file2
# ls -li
1282 -rw-r--r-- 2 root 0 root 0 Sep 23 13:19 file1
1282 -rw-r--r-- 2 root 0 root 0 Sep 23 13:19 file2
# find . -inum 1282
./file1
./file2