Every file on the Linux filesystem starts with a single hard link. The link is between the filename and the actual data stored on the filesystem. Even if you delete the original file, the hard link will still has the data of the original file because the hard link acts as a mirror copy of the original file. In this guide, we will see how to create and manage hard links
creating hard links
When we create a hard link to a file with ln, an extra entry is added in the directory. A new file name is mapped to an existing inode.
Both files have the same inode, so they will always have the same permissions and the same owner. Both files will have the same content. Actually, both files are equal now, meaning you can safely remove the original file, the hardlinked file will remain. The inode contains a counter, counting the number of hard links to itself. When the counter drops to zero, then the inode is emptied.
finding hard links
You can use the find command to look for files with a certain inode. The screenshot below shows how to search for all filenames that point to inode 674162. Remember that an inode number is unique to its partition.
symbolic links
Symbolic links (sometimes called soft links) do not link to inodes, but create a name to name mapping. Symbolic links are created with ln -s. As you can see below, the symbolic link gets an inode of its own.
Permissions on a symbolic link have no meaning, since the permissions of the target apply. Hard links are limited to their own partition (because they point to an inode), symbolic links can link anywhere (other file systems, even networked)
removing links
Links can be removed with rm.
Latest posts by Ruwantha Nissanka (see all)
- 4 ways to hide your identity using linux - January 18, 2021
- How To Install Kali Linux in Virtualbox - December 31, 2020
- Kali Linux : The OS That Hackers Use - December 31, 2020
- How to monitor user activity in Linux with Acct - December 30, 2020
- Debsecan : You will not miss another security update - December 28, 2020