LINKS

Jacer Dabbabi
2 min readFeb 3, 2020

What are links ?

In your Linux file system , a link is a connection between a file name and the actual data on the disk.

Types of links :

  • Hard links :

By definition , hard links are low-level links which the system uses to create elements of the file system itself, such as files and directories.

To create a hard link we can use the command : ln target linkname

  • Symbolic (soft) links :

The symbolic link is a file in its own right, but it does not contain a copy of the target file’s data. It is similar to a shortcut in Microsoft Windows .

To create a symbolic link we can use the command : ln -s target linkname

What is the difference between hard links and symbolic links ?

The difference between the two are significant. With hard links, you can only link to files (and not directories); you cannot reference a file on a different disk or volume, and they reference the same inode (index code) as the original source. A hard link will continue to remain usable, even if the original file is removed. However , if you delete a symbolic link, the target is unaffected. Also, if the target of a symbolic link is deleted, moved, or renamed, the symbolic link is not updated. When this happens, the symbolic link is called “broken” or “orphaned,” and will no longer function as a link.

For example, if we have a file name.txt. If we create a hard link to the file and then delete the file, we can still access the file using hard link. But if we create a soft link of the file and then delete the file, we can’t access the file through soft link and soft link becomes dangling. Basically hard link increases reference count of a location while symbolic(soft) links work as a shortcut.

To see the difference between how each type of link looks from a terminal window, issue the command ls -li. You will see how each is represented with slight variation from one another .

--

--