Difference between a hard-link and a symbolic-link (soft-link).

Moonage Volkova
2 min readFeb 1, 2021

--

A link in UNIX is like a pointer to a file. Creating links is a kind of shortcuts to access a file.

There are two types of links :

  1. Soft Link or Symbolic links.
  2. Hard Links.

These links behave differently when the link source is moved or deleted. Symbolic links are not updated; hard links always refer to the source, even if they are moved or deleted.

Now, we are going to explain the difference between a hard-link and a soft-link.

Hard Links:

A hard link is a shortcut to another file, it is linked with the inode of an existing file.

  • Each hard linked file takes the same inode number.
  • Hard links are not allowed for directories.
  • Removing any link, just reduces the link count, but doesn’t affect other links.
  • Even if we change the filename of the original file the hard links properly work.
  • It cannot be used across file systems.
  • If original file is removed then the link still shows the content of the file.
  • The size of any of the hard link file is same as the original file and if we change the content in any of the hard links then size of all hard link files are updated.
  • Data present in the original file will still be available in the hard links.
  • Hard links are kinda faster.

Command to create a hard link is:

ln <source> <link>

Symbolic Link (Soft links)

A symbolic link is a file-system object that points to another file system object. The object being pointed to is called the target.

  • Files that are soft linked take a different inode number.
  • Soft links can be used for linking directories.
  • Removing soft link doesn’t affect anything but removing original file, the link becomes “dangling” link which points to nonexistent file.
  • It can be used across file systems.
  • Soft links only point to the file name, it does not retain data of the file.
  • If the original file is removed, the link will not work as it doesn’t access the original file’s data
  • Soft links are kinda slower.

Command to create a Soft link is:

ln -s file_name softlink

--

--