Hard links and symbolic links - creation and differences
man ln in terminal of Linux (self-authorship)

Hard links and symbolic links - creation and differences

To use either of these two types of links (hard and symbolic) in your shell commands, it is necessary to know the function and use of the ln command (see manual) which, in a few words, is used to create links.

In this sense, links within the Linux file system refer to a file pointing or linking to another file. This explanation can be similar to the files in which it is possible to generate direct links in Windows, since this type of file can be accessed easily, without the need to search for the file (which will surely be in a difficult place to access).

Thus, in Linux there are two types of links, which will be explained below:

Hard links: They are rarely used because they have more disadvantages than symbolic links, for example:

- They cannot be created for directories, only for files.

- This type of links cannot link to file systems such as external disks.

To create a hard link, the following command is used:

                        ln [source] [name_link]

If we have a file named origen.txt we can create a physical or hard link as follows:

No hay texto alternativo para esta imagen

The new_origen.txt file looks like a normal file and so it is, when you edit this or the origen.txt file, whatever you do in either will be updated in both. The image below shows that if the original file is deleted, the file to which the link was created still contains the same content as the original file.

No hay texto alternativo para esta imagen


Symbolic links: Unlike hard links, these links are more common and possess a "power" that makes them special and significantly different from hard links: they can link to other file systems and directories. However, when the original file/directory is removed, the link will be broken.

To create a simbolic links, the following command is used:

                        ln -s [source] [name_link]

I will make an example with the same file name of the previous example and let's suppose that we create a symbolic link in that file with the command already mentioned. You can see how it differs from creating a hard link:

No hay texto alternativo para esta imagen

As it can be appreciated it contains at the end a kind of sign (->) which indicates its creation with symbolic link; now, if the original file is eliminated, we will have a message of the shell communicating us the absence of this file, reason why we could not accede to him:

No hay texto alternativo para esta imagen

Expand your knowledge by reading the ln command manual!


要查看或添加评论,请登录

Diana Parra的更多文章

社区洞察

其他会员也浏览了