The differences between hard and symbolic links.

Victor Rivera
4 min readFeb 4, 2020

We first have to breakdown and talk about the one thing that connects the links: the inode.

An inode is a data structure that describes the objects within the system as either a file or directory. This means that any folder or file you make on your computer will basically be recognized and labeled by the inode.

There is a command used to create links and that is the ln command. Note: By default, ln creates a hard link of the file you use ln with. Below is an example on how to create a hard link.

The syntax goes as follows: ln [name of file you want a link for] [name of the hard link to the file]

A hard link has the same inode value as the original, which makes them dynamic. The reason behind that is you can move the original around, rename it and it will still be linked to the original file. A point to note however is that a hard link cannot be moved around, it will stay in the directory and file system it was created in. More information to know is that a hard link still has actual file content, so once you access it you’ll see the content of original no problem. And what if you make multiple hard links? Same case scenario. If you want to see how many links you’ve made for said file; using ls -l will list all links via a column list and show the number of links total. Now what’s interesting is that, if you do delete the original file, the hard links will remain and still contain the content from the original file. Though another note is, we cannot make hard links for directories. What will happen is, it would put us in a endless loop that repeats itself, like Loki falling through Dr.Strange’s Portal in Avenger’s Endgame.

When using ls -l, it shows the number of links you made for the file, both symbolic and hard links. The 2 I circled is how many links I have to the file; named link. The command also lists files in the current directory in long format.

Now to create a symbolic link, this is how it is written on the command line:

And this is how it looks when you use ls -l on the command line:

With a symbolic link, it actually contains a inode value separate from the original. This means a symbolic link essentially acts like a bookmark to the original file. You click on the symbolic link and it directs you to the file you linked. When listing your files in long format, the Shell shows the name of your symbolic link pointing to the original file. All it has, is the path to the original. Symbolic links do not contain the contents of the original file. Now if and when you want to delete the original file and it has a symbolic link, this is what happens: Deleting the original file will turn the symbolic link into a link with nothing to reference. A blank bookmark. However if you delete the symbolic link, nothing happens to the original file. These two final points are the coolest things about symbolic links, which also showcases the benefits it. Symbolic links allow you to link files across different file systems and You can create a symbolic link for a directory, like this:

Syntax for creating a symbolic link to a directory goes as follows: ln [-s, — symbolic,] [name of directory you want to link] [name of symbolic link]

And that are the differences between symbolic and hard links, as well as how to create them yourself. I hope this was clear and informative! Any questions, comments, concerns; comment below or contact me at my email below.

victorxrivera.professional@gmail.com

--

--

Victor Rivera
0 Followers

Hey there, I'm Victor. I'm a student at Holberton School for Software Engineering!