What are hard and symbolic links, and what’s the difference between them

Stiven Gonzalez
2 min readFeb 5, 2021

In Unix-like operating systems such as Linux, “everything is a file” and a file is fundamentally a link to an inode (a data structure that stores everything about a file apart from its name and actual content).

Inodes

An inode is a data structure. It defines a file or a directory on the file system and is stored in the directory entry. Inodes point to blocks that make up a file.

Hard Link

A hard link is a file that points to the same underlying inode, as another file. In case you delete one file, it removes one link to the underlying inode. Whereas a symbolic link (also known as soft link) is a link to another filename in the filesystem.

A hard link to a file is just another link to this file’s inode. The command “ln” allows us to create a hard link to a file.

Soft, or Symbolic links

A symbolic link, on the other hand, is a link to another link in the file system. We can create a symbolic link by adding the option “-s” to our “ln” command.

What is the difference between hard link and Symbolic links

  • Symbolic links can be made with files and directories while hard links only between files.
  • Symbolic links can be made between different file systems, hard links
  • cannot.
    ¡Hard links share the inode number, symbolic links do not.
  • In symbolic links, if the original file or directory is deleted, the information is lost, in hard links, not.
  • Hard links are exact copies of the file while symbolic links are mere pointers or “shortcuts”.

Essentially, symbolic links are better than hard links when you need to access whole directories, or files on remote computers, and hard links are better when you know you’re going to modify the original file and want to keep an older version or it as well. One interesting note on symbolic links: they can be accessible from other file systems, not hard links.

Both hard and symbolic links are useful but have different purposes, and it’s important to know them well in order to avoid accidents when managing files.

--

--