What's a Hard Link and a Symbolic Link?
In this post, we’re going to discuss the difference between a hard link and a symbolic link, what they are, what they do, and which one of them is the better link.
A hard link is another version of an existing file on the Linux operating system.
Think of it as a complete copy of the file with nothing distinguishing them apart. Even the isode number (File identification number) is the exact same value. where you have the ability to make as many copies of the hard link from another hard link or the original file.
The ability of a hard link is to allow the accessibility of files, programs, and scripts from a different directory not located where the hard link was created. Using the hard link will have the same effect that using the original file would have. The only difference is that you’re using a different name to call that file. In which, the underlying code is the exact same and does the exact same command.
To create a hard link we only need to type in the command:
ln filename hlink1
In which [ln] means create link, the name is the name of the file you want to create, and hlink1 being the hard link you want to copy.
Now with symbolic links, the new file created is not a complete copy of the original file.
Soft links are files that point to another file (i.e. a shortcut to another file). because soft links don’t contain the data of their copied file their isode numbers are different.
However soft links are able to share themselves with other directories and other files not located in the same computer network. Meaning they’re more free to wander to new entry points.
In order to create a soft link we need to enter the command:
touch filename — in order to create a file, then…
ln — s file softlink1
Overall, each has their own benefits in certain situations. if you delete a hard link you won’t lose the data from the other hard links or the original file and vice versa. On the other hand if you delete a symbolic link, that link and the entry point are permanently gone and you have to create another one from scratch. Despite that soft links provide better mobility for files to reach outside directories.
Although hard links aren’t used that often anymore in modern times, both still provide beneficial value to coders.
P.S. if you want to find the iSode number of a file here’s the command: