What is the difference between a hard link and a symbolic link?

Yoyman Manuel Castellar Miranda
2 min readFeb 6, 2020

A hard link A hard link is a file that points to the same content stored on disk as the original file. A hard link is nothing more than a way to identify content stored on the hard drive with a name other than the original file.

To create a hard link first, create a new file.

touch filename.txt

Then you must to check the number of the inode.

ls -li filename.txt

1341693 -rw-r--r-- 1 joan joan 0 nov 17 22:50 filename.txt

The inode is 1341693. Currently there is only 1 file / entry in the system that is pointing to the same inode. Once the file is created, we will create a hard link to the file we just created by entering the following command in the terminal:

ln filename.txt filenamelink

“ln” means that is the command in charge of making links between files.

“filename.txt” is the path or name of the original file that we have on our hard drive.

“filenamelink” is the path or name of the hard link that we are going to create.

when the hard link is created you must to check the number of the inode from original file using the command viewed previously

ls li filename.txt
1341693 -rw-r--r-- 2 joan joan 0 nov 17 22:50 filename.txt

As you can see the inode number remains the same as before, but now there are 2 files / entries pointing to the same inode. These 2 files / entries are the original file plus the hard link we just created. Then we will check the inode number of the hard link that we have created by executing the following command in the terminal:

ls -li filenamelink
1341693 -rw-r - r-- 2 joan joan 0 Nov 17 22:50 filenamelink

Therefore it can be seen that both the hard link and the file we created point to the same inode.

Symbolic Links

They are the equivalent of what are the shortcuts in Windows. Symbolic links are more useful than shortcuts, since these can be used by programs to access or use the files to which the symbolic links point.

To create a symbolic we need to use this command.

ln -s origin_file.txt symbolic_link_name.txt

For example: Create a symbolic link from the / mnt / my_drive / movies directory to the ~ / my_movies directory you want to run:

ln -s /mnt/my_drive/movies ~/my_movies

The output will look something like this:

lrwxrwxrwx 1 linuxize users 4 Nov 2 23:03 symbolic_link_name.txt -> origin_file .txt

--

--