Explaining the difference between hard links & symbolic links using Bruce Lee

Source

(Note: this post assumes you know about the Linux terminal)

Hard links and symbolic links are pointers to files, but differ in their respective relationship to inodes.

An inode is a data structure that stores the data content, permissions, etc. about a file. It’s a map to all of that. On a computer, when you save files, those files are saved somewhere in memory and have an inode that they can refer to for information retrieval.

Which brings us to Bruce Lee.

Bruce Lee is the Bruce Lee.

Jason Scott Lee played Bruce Lee, in a film about the Bruce Lee.

The lens we will use to explore Bruce Lee will be through the timeframe of the film about Bruce Lee.

Bruce Lee can only be The Bruce Lee.

Jason Scott Lee had to be Bruce Lee, so he was not the Bruce Lee.

To create links, we use:

ln

To specifically create a soft link, we attach an -s flag:

ln -s

Changing the name of thebrucelee will not matter.

thebrucelee points to the inode, the address to reach the place in memory where that information (“Bruce Lee”) is stored, of the file. This content has not changed. This hard link is duplicate copy of the original file, a shortcut to the file. Editing it will make changes to the file. The hard link acts like the copy. The Bruce Lee, will always be, The Bruce Lee.

The soft link or symbolic link points to the inode through a file.

Source

The contents of the file could not be found because the soft link points to the name, that was changed, not the contents. Deleting the original copy will make any symbolic links pointing to the original copy disappear, but the duplicate hard link copy will still point to the file, and there will still be access to that file. In terms of our references: if thebrucelee is deleted, thebrucelee-hard still holds the contents; if brucelee is deleted, brucelee-soft is just a link to a non-existing file.

When we create a file, our file name makes a link to that data. When we create a hard link, we create another direct link to that data; when we create a soft link, we only make a link with the file name, and where it is.

If the source file is removed, the soft link is useless, the hard link will remain. Jason Scott Lee will not always be Bruce Lee. Bruce Lee will always be The Bruce Lee.


Like what you read? Give Jimmy Thong a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.