Hard and symbolic links on linux

Juan Sebastian Caicedo Alfonso
2 min readFeb 2, 2021

--

What is a hard link?

Hard links are mirrored copies from the original. When a hard link is created, all the content, the file permissions, and even the index number of the file are copied to the hard link.

This means the link content does not depend on the original file’s content. Since the link has a copy of the content, even if the file is removed, the link will still have the original content and nothing will be lost. However, if any change to the original file is made, either in the content or in the permissions for example. Those changes will be reflected on the hard link as well.

To create a hard link in linux, we use the ln command with the following synopsis:

ln originalfile linkfile

Where “originalfile” is the target and the “linkfile” is the name of the link we are about to create

For example, if you have a file named “my-summer-fling” and you want to create a hard link to it name “just-in-case”. You would need to use:

ln my-summer-fling just-in-case

What is a symbolic link?

Symbolic links or soft links are files with the original file’s address. When a symbolic link is created, it points to the original file and nothing else.

This means a symbolic link is just a file containing a different file address. It has a different index number and different permissions from the original file. And in case the original files is removed, the link will be meaningless since the file which it was pointing to does not exist anymore.

To create a symbolic link in linux we use the same synopsis as we use to create a hard link, but we add the option “-s” to the ln command. It will be as follows:

ln -s originalfile linkfile

To recreate the same example we used for creating a hard link, in this scenario you’ll have to type:

ln -s my-summer-fling just-in-case

--

--

No responses yet