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”

am2701
3 min readFeb 7, 2021

Prerequisites

What does “inode” mean ?

The inode (index node) is a data structure in a Unix-style file system that describes a file-system object such as a file or a directory. Each inode stores the attributes and disk block locations of the object’s data. File-system object attributes may include metadata (times of last change, access, modification), as well as owner and permission data. — wikipedia

What does “hardlink” mean ?

In computing, a hard link is a directory entry that associates a name with a file on a file system. All directory-based file systems must have at least one hard link giving the original name for each file. The term “hard link” is usually only used in file systems that allow more than one hard link for the same file. — wikipedia

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 ?

In computing, a symbolic link (also symlink or soft link) is a term for any file that contains a reference to another file or directory in the form of an absolute or relative path and that affects pathname resolution. — wikipedia

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.

Hard link cannot be created to a folder.

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

--

--