Hard Link vs Soft link

Hard Link:

Unix files consist of two parts: the data part and the filename part.
More than one filename can reference the same inode number; these files are called to be hard linked together.

Here two hard link files file-hard-a.txt and file-hard-b.txt reference same inode number.
Example:

[root@sunx4150 tmp]# touch file-hard-a.txt
[root@sunx4150 tmp]# ln file-hard-a.txt file-hard-b.txt
[root@sunx4150 tmp]# ls -ltri
34532 -rw-r--r-- 2 root root 0 Aug 20 10:09 file-hard-b.txt
34532 -rw-r--r-- 2 root root 0 Aug 20 10:09 file-hard-a.txt

Hard Link can not cross file system boundaries.

Soft Link:
There is a special file type whose data part carries a path to another file. Since it is a special file, the OS recognizes the data as a path, and redirects opens, reads, and writes so that, instead of accessing the data within the special file, they access the data in the file named by the data in the special file. This special file is called a soft link or a symbolic link.

Here you see that soft link file file-soft-b.txt reference file name file-soft-a.txt.

Example:

[root@sunx4150 tmp]# touch file-soft-a.txt
[root@sunx4150 tmp]# ln -s file-soft-a.txt file-soft-b.txt
[root@sunx4150 tmp]# ls -ltri
34532 -rw-r--r-- 1 root root 0 Aug 20 10:19 file-soft-a.txt
2344 lrwxrwxrwx 1 root root 15 Aug 20 10:19 file-soft-b.txt -> file-soft-a.txt

Soft link can be created across file system boundaries.

Leave a Comment

Your email address will not be published. Required fields are marked *

CAPTCHA * Time limit is exhausted. Please reload the CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top