Hard Links And Symbolic Links

Manuel Enrique Figueroa
3 min readSep 15, 2020

What are they?

Symbolic links and hard links all begin with whats called an inode. An inode is basically a system that stores the physical cordinates for a file on your drive. When you create a file and give it a name it is essentialy a Hard Link in itself since you are creating a Filename to a new inode. When a Hard Link is created it makes a text that points to the same inode as the orginal file. When a Symbolic Link is created it makes a text that points to the filename of the designated file.

Hard Links:

To create a Hard Link you are gonna wanna use the ln command → ln [filename] [hard_name]

Here are some examples of using the command:

here we use the command to create the link first_hard
Interestingly you can tell the difference between a hard link and a symbolic link since the hard link looks like a file and the symbo link takes on a sky blue color
If you want to view if a file has the same inode you can use the ls -lia command as shown in the picture
here you can see that our hard link and original file have the same inode which is the first 6 numbers a the start of the output

Symbolic Links:

To create a link you are gonna wanna use the ln command with the -s option like this → ln -s [filename] [Symbo_link_name]

Here are some examples of using the command:

First I start with a file (file1)
Now we use the command to create a symbolic link call first_symbolic which now points to the FILE NAME of file1
With the ls -lia command we can view what file our symbo link is pointing to
As you can see it is pointing to or original file

What will happen if I delete the file?

If you delete the file that the symbolic link points to the link will no longer function since it points to nothing. If you delete the file that a Hard link is pointing to it will still point to the inode of the orginal file in return using the same amount of disk space. This is what seperates Hard Links and Soft Links. Since a soft link only points to the filename when the file is deleted to link cant point anywhere. However a Hard Link can still point to the original file.

--

--

Manuel Enrique Figueroa
0 Followers

I am a current student at Holberton school of software engineering aspiring to have a career in full stack software engineering.