HARD LINKS AND SOFT LINKS — LINUX

Julian Tabares
2 min readFeb 2, 2021

Clone it or Point to it?

Despite the fact that both, Hard links and Soft links refer to a file, the do in very different ways.

If your are familiar with Windows OS, then, think of Soft Links (AKA Symbolic links) as a shortcut to a file.

A Soft link is a file that points to anothe file or directory, but does not contain all the data and size of the original one, it just redirects the user to it, besides, they have a different Inode number, therefore, if the original file is deleted, the Simbolic links become useless since they are pointing to a non existing file, but you can delete the Symbolic link and the original file remains unaffected.

Some additional caracteristics:

  • Permissions will not be updated.
  • They can cross the file system.

To create Soft links use the following command structure:

ln -s source_file myfile

Where “source_file” is the name of the existing file/directory you want to point to, and“myfile”is the name of the Soft link

Keep in mind that the destination file/directory should be within the same filesystem.

On the other hand, we have Hard links, You can think of Hard links as a copy of the original file: the have the same size and the same content, and Inode number but a different name, therefore you can delete either one of them, and the other one remains unaffected.

Some additional caracteristics:

  • Can`t cross the file system.
  • Can`t link directories.
  • If the permissions on the original file are changed, they are updated on the “copied” file.

To create hard links use the following command structure:

ln source_file myfile

Where “source_file” is the name of the existing file/directory you want to copy, and“myfile”is the name of the Hardlink

--

--