Hard link and a Symbolic link, any difference?

Juan Camilo Villa
Dev Genius
Published in
2 min readJun 9, 2020

--

In order to find differences between these two types of links we first have to define them:

Symbolic Link:

The easiest way to understand what a symbolic link is in Linux is to compare it to the “direct link” or “shortcut” in Windows. The file or directory is located at a single point on the disk and the links are a pointer against it. Each symbolic link has its own inode number which allows symbolic links to be made between different file systems.

To create links (both symbolic and hard links) we use the command ln. In this case, we will create a symbolic link (parameter -s) from the test file:

$ ln -s test link-to-test

Hard Link:

The hard links are to associate two or more files sharing the same inode. This makes each hard link an exact copy of the rest of the associated files, both data and permissions, owner, etc. This also implies that when changes are made to one of the links or to the file, these changes will also be made to the rest of the links.

Hard links cannot be made against directories or outside the file system itself.

We are going to create a hard link against the “test” file before and we will see that they effectively share inode and that the data is synchronized between both:

$ ln test link-hard-test
$ ls -li
73793 -rw-r — r — 2 juan juan5 2011–04–27 19:09 liaison-hard-test
73793 -rw-r — r — 2 juan juan5 2011–04–27 19:09 test

Differences between soft and hard links:

Symbolic links can be made to files and directories while hard links can only be made between files.
Symbolic links can be made between different file systems, hard ones cannot.
Hard links share the inode number, symbolic links do not.
With symbolic links, if the original file or directory is deleted, the information is lost, with hard links it is not.
Hard links are exact copies of the file while symbolic links are mere pointers or “shortcuts”.

In this blog we learned what the types of hard and symbolic links were, and their differences were also exposed. I hope it helped you, never stop learning!

--

--