Hard link vs Symbolic link

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.

  • 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.
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]

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.

  • 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.
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]

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

--

--

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