Home/Glossary/Hard link

Hard link

A hard link is a directory entry that associates a name with a specific inode on a filesystem, allowing multiple names to point to the same physical data.

A hard link is a directory entry that maps a filename to a specific inode number on a filesystem. In Linux, a file is fundamentally an inode containing metadata and data block pointers, while the filename serves as a pointer to that inode. All hard links to the same file are identical; the operating system does not distinguish between the original filename and any subsequently created hard links.

Technical Implementation

When a hard link is created using the ln utility, the link count within the inode increments by one. The filesystem only deallocates the disk space and deletes the inode when this count reaches zero. This ensures data persistence as long as at least one reference remains. However, hard links cannot span across different filesystems or partitions because inode numbers are filesystem-specific. Additionally, modern kernels prohibit hard links to directories to prevent infinite loops in the directory tree.

Hard links are a core component of efficient backup strategies. Tools like rsync or Time Machine use them to create incremental snapshots. If a file has not changed between backups, the system creates a hard link to the existing data instead of duplicating it. This approach allows for multiple "full" backup views while only consuming disk space for new or modified files. You can verify shared inode numbers and link counts using the ls -li command.