Glossary

Hard Link

A hard link is a directory entry that points to the same inode as an existing file. Two hard-linked names are indistinguishable: they share permissions, owner, content, size, and inode number. The file is deleted only when the last hard link to it is removed and no process has it open.

ln original.txt alias.txt        # create a hard link
ls -li                            # same inode number for both
stat original.txt                 # link count shows 2

Hard links cannot cross filesystem boundaries (inode numbers are per-filesystem) and, by default, cannot point to directories (that would risk circular directory structures). Unlike symlinks, they do not become "dangling" when one name is removed: the other names still exist, and the data is safe.

Hard links are used under the hood by backup tools like rsync --link-dest and rsnapshot to deduplicate unchanged files between snapshots, saving enormous amounts of disk. They are also how git's object store works internally in some configurations. For day-to-day use, symlinks are usually preferable because they are explicit and can cross filesystems, but hard links remain the more efficient of the two when their constraints are acceptable.

Related terms: Symbolic Link, Inode

Discussed in:

Also defined in: Textbook of Linux