What is a hard link?
Welcome to the next pikoTutorial!
A hard link is essentially an additional name for an existing file on a filesystem. Unlike symbolic (soft) links, which point to a file by its pathname, hard links are direct pointers to the file’s inode. An inode is a data structure on a filesystem that stores information about a file, such as its size, permissions, and data block locations. Because hard links point directly to the inode, they remain valid even if the original file is moved or renamed. In other words, even if the file is removed, the file data remains accessible as long as at least one hard link points to that file.
How to create a hard link?
To create a hard link, use ln
command together with the path to the original file and path to the hard link:
ln /path/to/original/file /path/to/hard/link
Remember that hard links can only be created for files, not directories. This limitation helps to prevent file system corruption and unsolvable complexities in the directory structure, such as creating loops that could make the filesystem traversals difficult or impossible.