Difference between Soft link vs Hard link

Link is a mechanism of creating a shortcut to the original file or directory which contains information about its files or directories.

What is Soft link?

A symbolic link, also known as symlink or soft link, is a special type of file that points to source file or directory in Linux.

It is like a shortcut in Windows which contains the path of the original file and not the contents.

In general, Symbolic links are used to link libraries and log files & folders on mounted NFS (Network File System) shares.

Please refer the following article to remove/delete Symbolic Links in Linux

What is Hard link?

Hard link is a mirror copy of the original file. Deleting the original file will not impact anything, because the hard link file, will act as a mirror copy of the original file.

Why we need to Create a link file instead of Copying them?

Creating a Link file is specifically useful when the same file is kept in multiple location with updated contents.

Copying a file to another location, will merely copy the content of the file and it will never get updated from the source file.

The contents of the file may vary from time to time.

Difference between Soft link vs Hard link

I have included possible difference between the soft link and hard link in the below table.

S.NoSoft LinkHard Link
1Soft link is similar to the file shortcut in Windows.Hard link is a mirror copy of the original file.
2Soft link can be referred as Symbolic link or symlink.Hard link has no other names.
3Changes in both the files will reflect simultaneously.It is like a soft link.
4Soft links can be created on different file systems.Hard link can only be created on the same file system.
5Soft link can be created to files and directoriesOnly files can be linked
6It has different inode number and file permissions compared to the original file.It has the same inode number and file permissions.
7It contains the path of the original file and not the contents.It contains the actual contents of the original file.
8When the original file is removed, the link will be inaccessible because it points to a non-existent file. This is called the hanging link.Nothing happens when the original file is removed.
9Soft link can be created using the following command (ln -s [source-filename] [link_name])Hard link can be created using the following command (ln [source_filename] [link_name])
10Soft link file contains a special symbol “l” in the file permission field.There is no special symbol as such.
11Soft link file can be found using the following command (find / -type l)Hard link file can be found using the following command (find / -samefile [source_filename])
12A broken soft link can be found using the following command (symlinks [path/to/directory]).Not applicable

Conclusion

This article portrays the difference between Soft & Hard link in general.

Do share with others, if found useful!!!

About Magesh Maruthamuthu

Love to play with all Linux distribution

View all posts by Magesh Maruthamuthu

Leave a Reply

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