Difference Between Hard link and Soft link

In computer networks, links are the pointers associated with files and directories. These links are of two types: Hard Links and Soft Links. A hard link is a direct reference to a file, while a soft link is a reference by name. Thus, a soft link points to a file by its file name.

Read this article to find out more about hard links and soft links and how they are different from each other. Let's start with a basic overview of hard links and soft links so that it becomes easier to differentiate them.

What is a Hard Link?

The method of direct linking of two files in a same file system is referred to as the hard link. Hard links use the index node (inode) number for the identification of a file. Since hard links point to inode, they cannot be implemented on directories.

The "ln" command is executed to create a hard link. This command creates another file on the command link that is used to refer the original one. Although, both the original file and the hard linked file have the same index node (inode) number and content. Consequently, both files have the same set of permissions and the same owner.

If we removed the original file, then it will affect the hard linked file. Thus, the hard linked file will exist even after the removal of the original file. Hard links consume less memory space and they can be linked only to its own partition. In the case of hard links, the relative paths are not allowed.

What is a Soft Link?

A file can be accessed through many references. All of this point to a specific file is known as a soft link. In other words, the link to a file in which the file is pointed by its file name is known as soft link. Thus, a soft link is an alias or alternate path to the original file. Soft link does not use index node (inode) number. Soft links are also referred to as a symbolic link, because they contain the name of the target file of the link.

While accessing the file through the soft link, it redirects the link to the target file through the path provided in the subject of the soft link. The major advantage of the soft link is that the deletion and creation of the soft links do not influence the original file. The soft links can have an absolute or relative path as their part.

Difference between Hard Link and Soft Link

The important differences between Hard Link and Soft Link are highlighted in the following table −

S. No. Hard Link Soft Link
1. A file that has a hard link can be accessed using multiple names. These names are known as hard links. A file can be accessed through many references. All of this point to a specific file known as a soft link.
2. Once the file is deleted, the link would still be valid. The file can be accessed even after it has been deleted. Once the original file has been deleted, the link becomes invalid.
3. The inode number remains the same. The inode number is different.
4. The command used to create a hard link is 'ln'. The command to create a soft link is 'ln s'.
5. It consumes less memory. It consumes more memory.
6. It can be linked to its own partition only. It can be linked to other file systems and can be networked too.
7. It doesn't have a relative path. It has a relative path.


The most significant difference that you should note here is that a hard link is an alternate path of the original file that uses inode to access the target file, whereas a soft link is an alternate path to access the target file but does not refer inode to access it.