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

“when you see a hardlink you bray once, when you meet a symbolic link you bray twice”

Prerequisites

What does “inode” mean ?

What does “hardlink” mean ?

What does that mean ?

They are kind of shortcuts in the Linux/Unix world. Well, symbolic link can exist in the Windows world too, but for the simplicity of our explanation, let’s just work with the comparison that symlink is kind of a shortcut for now.

What does “symbolic link” mean ?

What does that mean ?

Files in Linux/Unix are not stored in directories. Files in Linux are assigned an inode number which Linux uses to locate files. Each file can have multiple hard links which are located in various directories.

Like a diagram is always better than a long speech …

Some commands

To create a hardlink

ln fileA fileB

Where fileA is the original file and fileB is the name you want to give to the hardlink.

If you now remove the original file and open the hard link, you will still be able to see the content of the original file.

To create a symbolic link

ln -s fileA fileB

Where fileA is the original file and fileB is the name you want to give to the symbolic link.

If you remove the original file, the symlink will still be there. If you try to access the content of the original file through the symbolic link after removing the original file, you will get a message saying there is no such file or directory.

To resume