Differences between hard and symbolic links

Gabriel Martinez
3 min readFeb 3, 2021
Photo by Bryson Hammer on Unsplash

It was not until I played around with hard and soft <symbolic> links that I understood how they really worked. To start a hard link is basically a copy of another file both pointing at the same spot at the hard drive. Now, if the original file gets deleted the hard linked file will still function because both were looking at the same spot. One thing though, if one hard link gets updated, all the other will also. Remember they are copies, monkey see monkey do.

Soft links in the other hand do not point to the original spot at memory as a hard link, they point to the file it is linked which in turn points to a spot at the hard drive. In contrast to hard links if the original file gets deleted or its name changed, link will go dangling meaning it will not function. They do offer portability which can be linked at different file system and take up less memory.

Learn more about file system:

Below are some images of how hard and soft links work

As you see in the image above “test1.txt” file is the original file created. With “ln” command no options just original file name followed by hard link file name we have created a hard link. Now as you see when the “ls -l” command is done the first time you can see they practically mirror themselves. As you follow through the commands you see they have the same text written in them and when test1.txt file is renamed nothing happens to the hardlink.txt file, it still has the original text written in it. As we move further one with the commands you can also see the hardlink.txt file is not affected by the removal of the original file, you can still access it.

In the image above we start with the first line of command creating a soft link, same as hard link but with “-s” prefix option. After creating the soft link file named “softlink” you see it points to test3 file and has the same written text as test3. As said before, because a soft link just points to the file when the original file (test3) gets its named is changed softlink file goes dangling therefore you will not get to access it. To confirm this you see softlink file pointing at test3 (now test4) in red but if we change test4 name to its original name test3 softlink file works normally again. Soft links will do mirror the info inside the original file name if it gets updated and vice versa.

I hope this will help you understand about how hard and soft links works. Please leave a comment if you found this blog useful as well any recommendations to improve it. Thank you for taking the time to read me!

--

--

Gabriel Martinez
0 Followers

Currently Holberton Student, aspiring nomad programming life