Difference between Hard link and Soft link

Hard Link :
A hard link acts as a copy (mirrored) of the selected file. It accesses the data available in the original file.
If the earlier selected file is deleted, the hard link to the file will still contain the data of that file.

Soft Link :
A soft link (also known as Symbolic link) acts as a pointer or a reference to the file name. It does not access the data available in the original file. If the earlier file is deleted, the soft link will be pointing to a file that does not exist anymore.

Some notable differences between the two are listed below:



Comparison Parameters Hard link Soft link
Inode number* Files that are hard linked
take the same inode number.
Files that are soft linked
take a different inode number.
Directories Hard links are not
allowed for directories.
(Only a superuser* can do it)
Soft links can be used for
linking directories.
File system It cannot be used
across file systems.
It can be used
across file systems.
Data Data present in the original
file will still be available
in the hard links.
Soft links only point to the
file name, it does not retain
data of the file.
Original file’s deletion If the original file is removed, the link
will still work as it accesses the data the
original was having access to.

If the original file is removed, the link
will not work as it doesn’t access the
original file’s data.
Speed Hard links are comparatively faster. Soft links are comparatively slower.

Note:

  • Inode number – Index node number is a unique number assigned to all files in a Linux/Unix system.
  • Superuser – A superuser has more rights compared to an ordinary user. They can change file ownership and set permissions.

Diagrammatic representation:


GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.