The difference between a hard link and a symbolic link, and other miscellaneous information on the topic

Octave Collombel
2 min readFeb 2, 2021

In Computing, more specifically in Unix-like operating systems, you are able to create “links” between files using the shell (the interface that allows you to interact with the operating system through the command line), allowing the user to create dependencies.

More specifically, we can distinguish between two types of links, symbolic links, and hard links.

Symbolic links are essentially text strings that point to a “target” file, they can be safely deleted without repercussion on said target file, and if that target is moved or deleted, the symbolic link will remain, now pointing to an empty location. Below is an example of how to create a symbolic file, in which “origin” is the target file, and “linkto” is the symbolic link. (The “ln” commands is what allows us to create the link, while the “-s” argument is what makes it specifically a symbolic link.)

$ ln -s origin linkto

Hard links are a little different from symbolic links, instead of merely referring to another file, a hard link is essentially a copy of the target file, even if you delete it, the hard link will still contain the data of the original file.

At this point, you might be wondering why you would ever create a hard link of a file, when you could simply copy it to another location and not have to deal with new concepts. As it turns out, there is a key difference in the behavior of hard link that makes them desirable in certain situations.

Hard links reflect the changes made to their target file, and the other way around, that is to say that if you modify any of the two files in any way, the change will also be done in the other. Again, below you will find an example of how to create a hard link, in which “origin” is the target file, and “cloneof” is the hard link. (Notice how this time we don’t use the “-s” argument, as we are making a hard link.)

$ ln origin cloneof

And I believe that covers the extent of my knowledge on link files, thanks for reading.

--

--