Should I use symbolic links? Not so hard-link decision

Diana Henao
3 min readFeb 7, 2021

When we refer to symbolic links or hard links, we are talking about a file referenced by multiple names in both cases. In which cases should I use one or the other type of link? let’s analyze it.

Photo by Shahadat Rahman on Unsplash
A hard link is like having two doors to the same room.

Some years ago only hard links existed.

In summary, hard links create “additional entries” to a file. It is like having two doors to the same room. However, hard links have some limitations. For example, HL can’t be used on a file that is not on the same disk partition. Additionally, and as I have commented implicitly, you can only create hard links to files, never to folders.

Symbolic link is like having a file or folder in more than one place at the same time
A symbolic link is like having a file or folder in more than one place at the same time

In this way, and to solve these limitations, symbolic links or symlinks were created. Unlike HLs, symbolic links are allowed in both files and folders. A symbolic link is like having a file or folder in more than one place at the same time(bilocation! :o).

You can see a summary of what is analyzed, in the following figure:

To create each type of link:

To create either of the two types of links, we can use the ln command. The only thing that differentiates how to create the hard link from the symbolic link is the -s option (for symbolic). For more detail look at the following examples.

Hard link: In this case, all we have to do is use the ln command, followed by the reference file and the name that we want to assign to our hard link. All we have to do is use the ln command, followed by the reference file and the name that we want to assign to our hard link. To verify that the link has been created, you can observe the number after the execution permissions when listing the files contained in the folder. In this case, we have 2 files connected.

Symbolic link: To create a symbolic link it is only necessary to add the -s option to the ln command. Unlike the hard link, the symbolic link is easily detectable by listing the files in the current directory. An “l” can be seen before the execution permissions, in addition to the fact that the symbolic link is pointing to the reference file (->).

Thus, the next time you have to choose what type of link to create, you can make a decision based on the advantages and limitations offered by each link type ;).

References:

  • Danesh A & Jang M. 2001. Mastering Linux, 2nd Edition. Sybex.
  • LeBlanc DA & Blum RK. 2007. Linux for dummies, 8th Edition. Wiley Publishing Inc.

--

--

Diana Henao

Programmer in training, because there is always a lot to learn. I’m not the best, but I’m trying my best!