Hard link vs. Symbolic link

Julian Torres
4 min readJun 8, 2020

What is a hard link?
They are the links that associate two or more files sharing the same inodo(information about the file or folder stored on your hard drive).
Simply put, a hard link is a file that points to the same content stored on disk as the original file.
The original files and hard links will have the same ido and consequently both will be pointing towards the same content stored on the hard drive, as shown in this image.

How to create a hard link?
1. Create a file with the following command:

touch hard_link.txt

2. Now we will consult your inodo number by running the following command in the terminal:

ls -li hard_link.txt
271059
-rw-rw-r-- 1 vagrant vagrant 0 Jun 8 22:43 hard_link.txt

The inodo of the file is the first field, and the number of inodos it points to is the third field of the result.

3. Now we will create a hard link to the file we just created, with the following command:

ln hard_link.txt enlacegeekland

This breaks down the command:
ln: This is the command in charge of linking between files.
geekland.txt: This is the path or name of the original file that we have on our hard drive.
enlacegeekland: Corresponds to the path or name of the hard link that we are going to create.

We run the command again to verify that the link was created and that the inodo remains the same:

ls -li hard_link.txt
271059 -rw-rw-r-- 2 vagrant vagrant 0 Jun 8 22:43 hard_link.txt

The inodo number remains the same, but now there are 2 files pointing towards the same inodo. These 2 files are the original file plus the hard link we just created, to check the hard link inodo number we run the following command:

ls -li enlacegeekland
271059 -rw-rw-r-- 2 vagrant vagrant 0 Jun 8 22:43 enlacegeekland

It is observed that both files point to the same inodo and make the same information stored on the hard drive.

What is a symbolic link?
They are very similar to Windows shortcuts and are the ones that users use on a regular basis.
symbolic links point to the name of a file and the file points to content stored on our hard drive, as seen in the image:

How to create a symbolic link?
1.Create a file with the following command:

touch symbolic.txt

2. Now we will consult your inodo number by running the following command in the terminal:

ls -li geekland.txt
271062
-rw-rw-r-- 1 vagrant vagrant 0 Jun 8 23:20 symbolic.txt

The inodo of the file is the first field, and the number of inodos it points to is the third field of the result.

3. Now we will create a symbolic link to the file we just created, with the following command:

ln -s /home/vagrant/symbolic.txt /home/vagrant/symbolic/enlacegeekland

This breaks down the command:
ln: This is the command in charge of linking between files or folders.
-s: This is the part of the command that indicates that the type of binding we want to create is a symbolic link.
/home/vagrant/symbolic.txt: This is the path and name of the original file we have on our hard drive.
/home/vagrant/symbolic/enlacegeekland: Corresponds to the path and name of the symbolic link we are going to create.

We run the command again to verify that the link was created and that the inodo remains the same:

ls -li symbolic.txt
271062
-rw-rw-r-- 1 vagrant vagrant 0 Jun 8 23:20 symbolic.txt

The inodo remains the same and only has one entry despite the creation of the symbolic link, we will check the ido number of the hard link that we have created by running the following command in the terminal:

ls -li enlacegeekland
271065 lrwxrwxrwx 1 vagrant vagrant 26 Jun 8 23:27 enlacegeekland -> /home/vagrant/symbolic.txt

the original file and the link we created have an inodo diferente.no are pointing towards the same content since the original symbolic.txt file is pointing towards a content stored on our hard drive, and the symbolic link is pointing to the name of the original file.

Hard link and symbolic link differences

º Symbolic links can be made with files and directories
º Hard links can only be made between files
º Hard links are exact copies of the file, while symbolic links are pointers
º Hard links share the number of inodo, the symbolic ones do not.
º In symbolic links if the original file or directory is deleted, the information is lost, in the hard ones not.

--

--