Differences between Hard Link and Symbolic Link — Linux

Cristian Fayber Pinzon Capera
3 min readFeb 6, 2021

Before talking about the differences, I want to make known the meaning of each one

Hard link

A hard link is merely an additional name for an existing file on Linux or other Unix-like operating systems.

Any number of hard links, and thus any number of names, can be created for any file. Hard links can also be created to other hard links. However, they cannot be created for directories, and they cannot cross filesystem boundaries or span across partitions.

Symbolic Link (Soft link)

Soft links is a special kind of file that points to another file, much like a shortcut.

Unlike a hard link, a symbolic link does not contain the data in the target file. It simply points to another entry somewhere in the file system. This difference gives symbolic links certain qualities that hard links do not have, such as the ability to link to directories, or to files on remote computers networked through NFS. Also, when you delete a target file, symbolic links to that file become unusable, whereas hard links preserve the contents of the file.

Now we go specifically to the differences…

  • A soft link does not contain the data in the target file.
  • A soft link points to another entry somewhere in the file system.
  • A soft link has the ability to link to directories, or to files on remote computers networked through NFS.
  • Deleting a target file for a symbolic link makes that link useless.
  • A hard link preserves the contents of the file.
  • A hard link cannot be created for directories, and they cannot cross filesystem boundaries or span across partitions.
  • In a hardlink you can use any of the hardlink names created to execute a program or script in the same manner as the original name given.

How to do them

Well, you can create a hard link to an existing file by using the command ln file_name hardlink

Now let’s create a soft link to compare with the hard link we created above.

For our example let us first create a file. If we type touch example1 hit enter. We can create a file. Now to create the soft link.

If we type in the shell ln -s example1 softlink we create a soft link between the files. See the example below.

--

--