Hard and Symbolic link in Linux.

Esneider Granada Valencia
2 min readFeb 12, 2021

Hard Link

The hard links associate two files in the same nodo, so each hard link is the exactly copy of the file that hard link points.

We could make a hard link by the following way:

$ ln test enlace-duro-test
$ ls -li
73793 -rw-r--r-- 2 user10 user10 5 2011-04-27 19:09 enlace-duro-test
73793 -rw-r--r-- 2 user10 user10 5 2011-04-27 19:09 test

In the example above we could see that the command to create the hard link is a direct reference to the file.

Symbolic Link

While hard link points to a file in direct way, a symbolic link can make reference to a file that is not in the currently directory, so the symbolic link could a different name.

$ ln -s test enlace-a-test

With the option -s, the system create a symbolic link that points to a file.

$ ls -l
lrwxrwxrwx 1 user10 4 2011-04-27 18:59 enlace-a-test -> test
-rw-r--r-- 1 user10 0 2011-04-27 18:58 test

Some differences between hard and symbolic links are:

  • Symbolic links can be made with files and directories while hard links only between files.
  • In symbolic links, if the original file or directory is deleted, the information is lost, in hard links, not.
  • Hard links are exact copies of the file while symbolic links are mere pointers or “shortcuts”.

--

--