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

In this introduction to hard links and symbolic links, we will first try to learn and define what each one means.

Victor Plaza
2 min readSep 15, 2020

Hard Link Definition:

A hard link is nothing more than a label or a new name associated with a file. It is a way of identifying the same content with different names. This link is not a separate copy of the previous file but a different name for the exact same content.

To create a hard link in Linux from the file file.txt to new_name.txt, we execute:

$ ln file.txt new_name.txt

The link will appear as yet another file in the directory and will point to the same content of file.txt. Any changes made will be reflected in the same way for both file.txt and new_name.txt.

A link can be deleted using the rm command in the same way that a file is deleted, however the content of the inode will not be removed as long as there is a hard link that refers to it. This can have several benefits, but it can also complicate the task of keeping track of files. A hard link also cannot be used to reference directories or files on other computers.

Symbolic link:

A symbolic link, also known as a symlink or soft link, is a special type of file that points to another file or directory.The command for creating a symbolic link to a directory is the same as when creating a symbolic link to a file. Specify the directory name as the first parameter and the symlink as the second parameter.

For example, if you want to create a symbolic link from the /mnt/my_drive/movies directory to the ~/my_movies directory you would run:

A symbolic link can also be defined as a tag or a new name associated with a file, but unlike hard links, the symbolic link does not contain the data of the file, it simply points to the registry of the file system where the data is located.

--

--

Victor Plaza
Victor Plaza

No responses yet