Hard link vs Symbolic link

This blog post describing the differences and characteristics between Hard link and symbolic link in Linux.

image 1. Graphic representation of Hard link and Symbolic link

What does link mean?

A file on a computer is a collection of data that has a specific physical location. Therefore, to access a file, we must know where it is physically stored. for them we require an inode. An inode contains the characteristics of a file, directory or any other object that the file system may contain. These inodes are not what we commonly see, what we usually do is give files or documents a name, and that is where the concept of a link comes in, because by naming we create a pointer to that inode or information from our file and that is the link.

Hard Link

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.

Characteristics:

  • Links have actual file content.
  • Any change in the data of any of the files is reflected in the hard link
  • Removing any link only reduces the number of links, but does not affect other links.
  • We cannot create a hard link for a directory to avoid recursive loops.
  • If the original file is deleted, the link will still show the contents of the file.

To create and see a hard link in Linux from the file fileale.txt to filenewname.txt, we execute:

Image2. create hard link
  1. first with the ls command (list of files and directories) you can see I have a file fileale.txt
  2. now to create a hard link we use the ln command, like this:
$ ln [original file name] [hard link name]

3. Finally, in order to see that it was created, we use ls -l and as you can see in the image2 my original file and my hard link are underlined, the hard link has he same characteristics of the original file

Symbolic link

We just saw that the hard links point to a file stored on our hard drive. In contrast, symbolic links point to the name of a file and later the file points to inode.

Characteristics:

  • Soft Link contains the original file path and not the content.
  • Removing the symbolic link does not affect anything other than removing the original file, the link becomes a “dangling” link pointing to a non-existent file.
  • A symbolic link can link to a directory.
  • Link Across File Systems — If you want to link files across file systems, you can only use symbolic links / soft links.

To create and see a symbolic link in Linux from the file fileale.txt to filenewname.txt, we execute:

image 3. Create symbolic link
  1. first with the ls -l command (list of files and directories) you can see I have a file fileale.txt
  2. now to create a symbolic link we use the ln command, like this:
$ ln -s[original file name] [hard link name]

3. Finally, in order to see that it was created, we use ls -l and as you can see in the image3 my original file and my hard link are underlined, the symbolic one is pointed to the original file name.

Conclusion

As a conclusion we are going to see a comparative table with the main characteristics of the link types:

Table 1. link types comparison

References

https://www.tecmint.com/create-hard-and-symbolic-links-in-linux/#:~:text=In%20Unix%2Dlike%20operating%20systems,underlying%20inode%2C%20as%20another%20file.

https://www.youtube.com/watch?v=kYonC93SvpE

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store