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

Gabriel Vazquez
2 min readSep 16, 2020

--

To understand the difference between a hard link and a soft link we have to first understand what they have in common. In crude terms, they are both ways of connecting you to a file. The difference is how they do this.

Let’s start with hard links. A hard link is basically just another shorter name for a file that already exists. Multiple hard links can be established, even stacking above one another, but they only work for files (i.e. not directories etc). They essentially serve as shortcuts, linking from within other files to the original long-named version.

To create a hard link we use the command ln. For example we would type in out terminal ln (the_file_you_want_to_link_to) hardlink. This would create an inode, or add it to a catalog of files so-to-speak, and establish a functional link between the file and wherever you chose to input the hard link.

Soft links, however, are more abstract. Instead of being an abbreviated version of a link, it’s more-so just a road sign that points you in the direction of the file you seek. The fact that it doesn’t carry any weight of the file within gives it the ability to link to destinations that hard links cannot, such as directories, partitions and remote files.

By using the same command, ln, but finishing it like so we create a soft link: (the_file_you_want_to_link_to) softlink. The main differences between the two are that the hard link carries the content of the file it points at, deleting the original file doesn’t affect it as the contents of it are copied onto the hard link. Whereas, with the softlink, if the target file is deleted the soft link ceases to function.

In summary, a hardlink creates a copy in memory of the object while a softlink only points to it’s location in memory.

--

--

No responses yet