Hard Link vs. Symbolic Link

HUMBERTO TEJADA ESPINOZA
4 min readOct 4, 2021

--

Have you ever heard some of these words? Are you curious to know what they are? What are they used for? Why are they important? Well, here we will explain it to you in the most simple and summarized way possible, so … LET’S GO!

Image from scriptcrunch

Let’s start with the bases, first of all, we need to know what is INODE:

Image from codigofacilito

Generally speaking, an Inode contains the metadata of a file, this metadata includes information such as size, permissions, creation date, owner, and more. When a user tries to access a file or directory, the Inode table retrieves the file using its Inode identification, this is unique for each file or directory. For this reason, when these are created, they are associated with a unique INODE ID for each one. Normally the files have different INODE IDs, but there are ways for two files to share the same Inode and one of them is through HARD LINKS.

What is a HARD LINK?

A HARD LINK is an exact copy of a file, however, it is not a reference to the file as such, but a reference to its INODE, that is, a HARD LINK what it does is point the folder or file directly to the INODE of the database. This means that even if you delete or modify the file or directory to which you had linked, the link will continue to work since it points directly to the data, it would be like having the files twice but occupying space only once, and without worrying that one of the two links disappears while the other remains. HARD LINKS share the same INODE, no matter how many HARD LINKS you create from the same file, they will all share the same INODE.

Putting it in a more realistic example comparing it with everyday life is like having doors (HARD LINKS) that lead you to the same room (INODE) ​​and the content of the room is the stored data (INODE METADATA); Each door is independent of the other so if you delete the original door or some other door, others will still be able to continue working as long as the room exists.

What is a SYMBOLIC LINK?

A SYMBOLIC LINK is like the direct access you have on your desktop, the SYMBOLIC LINK creates a link from a point to where your original file or directory is, that is, the file or directory is in a specific place on the disk and the SYMBOLIC LINKS are a pointer to it. Each symbolic link has its own inode number which allows making symbolic links between different file systems. But there is something else about the SYMBOLIC LINKS, if a SYMBOLIC LINK were to be eliminated nothing would happen because the source (original file or directory) is still present, it would only be enough to create another SYMBOLIC LINK, or if we had other SYMBOLIC LINKS these would still follow running. But if you were to delete the original file or directory, any SYMBOLIC LINK created from it would become obsolete because the source was lost.

If we wanted to put it in a more realistic example comparing it with everyday life we ​​could compare it in the following way, the original file would be the Coca Cola factory, and the SYMBOLIC LINKS would be like the stores that sell Coca Cola products (suppose they only sell Coca Cola products); If a store closed there would be no problem because the factory is still there, there are other stores that continue to sell their products, so losing a store is irrelevant, but if the Coca Cola factory closed (referring to eliminating the original file) these stores would be obsolete because they have nowhere to get their resources.

Now that you know what a HARD LINK and a SYMBOLIC LINK is … Which one do you think is more useful?

--

--