Difference between Soft Links and Hard Links in Linux

Link file is a short cut file to the original file. There are two types of links files available in Linux. The links in Unix like OS are essentially the pointers which associate to the files and directories. Here we will see the difference between Soft Links and Hard Links in linux.

There are two types of link files available in Linux.

  1. Soft Link
  2. Hard Link

Soft Link

  1. Soft link is a short cut file. If original file deleted, there is no use of short cut file. ie. we can’t access the original data by selecting link file.
  2. Soft link can be applied on both files and directories.
  3. Soft Link files can be stored in any file system. ie., the original file can be in one file system and the link file can be on another file system. If we edit any file, the linked files are also updated automatically.
  4. When we create a soft link file, there are are full permissions always.
  5. The soft link file and the original file inode numbers are different.
  6. The size of the soft link file is same as the length of the original file name.

Soft link can be created using following commands.

$ ln -s (to create a soft link)
$ ln -s /root/script /root/Desktop/script (to create a link file for the script and stored on root Desktop)

Hard Link

  1. Hard link in nothing but a backup file. If the original file is deleted, there is no effect on hard link file. ie. we can access the original file data even though the link file is deleted.
  2. Hard links can be applied on files only not on directories.
  3. Hard link files can be stored on the same file system. ie., original and hard link files both should be in the same file system not on different file systems.
  4. The inode numbers are same for original and hard link files.
  5. If the original is edited, the updations are applied on both original and hard link files.
  6. The size of the hard link file is same as the size of the original file.

Hard links can be created using following commands. 

$ ln /root/file /root/Desktop/file (to create a hard link)

Conclusion

Hence we learned difference between Soft Links and Hard Links in Linux.

I hope I helped !!

Read Also : Difference Between File Systems in Linux

Share on:

Ravindra Kumar

Hi, This is Ravindra. I am founder of TheCodeCloud. I am AWS Certified Solutions Architect Associate & Certified in Oracle Cloud as well. I am DevOps and Data Science Enthusiast.

Recommended Reading..

1 thought on “Difference between Soft Links and Hard Links in Linux”

Leave a Comment