The Linux Concept Journey — Hard Link

Shlomi Boutnaru, Ph.D.
2 min readApr 27, 2024

--

As mentioned in previous writeup, an inode is data structure used by Unix/Linux like filesystems in order to describe a filesystem object (https://medium.com/@boutnaru/linux-what-is-an-inode-7ba47a519940). Thus, each hard link has the same inode value as the original file it points to — as shown in the screenshot below. When removing a hard link it just reduces the “link count” (think about it as a reference count), but it does not affect other links (the file is removed only when the count reaches “0”). Each hard link has a different file name and if the size of the content of one link changes then all the hard links file sizes are updated (https://www.geeksforgeeks.org/soft-hard-links-unixlinux/).

Overall, we have a couple of limits regarding hard links which includes the fact we can create a hard link only for regular files (not including special files or directories). Also, we can not use a hard link to point to a file in a different filesystem (https://www.redhat.com/sysadmin/linking-linux-explained) — as shown in the screenshot below.

Lastly, we can use the “ln” command line utility in order to create hard links (https://man7.org/linux/man-pages/man1/ln.1.html) — as shown in the screenshot below. It is based on the “link”/”linkat” system call which is described as “make a new name for a file” (https://man7.org/linux/man-pages/man2/link.2.html).

See you in my next writeup ;-) You can follow me on twitter — @boutnaru (https://twitter.com/boutnaru). Also, you can read my other writeups on medium — https://medium.com/@boutnaru. You can find my free eBooks at https://TheLearningJourneyEbooks.com.

--

--