Reference

Hard Link

A hard link is an additional directory entry pointing to the same inode as an existing file. Multiple hard links are equally valid names for one set of data, and the file's blocks are freed only when the last link is removed.

APIs & internalsGeneral

Hard Link

Also known as: hard links explained, hardlink vs symlink, hard link

A hard link is an additional directory entry pointing to the same inode as an existing file. Multiple hard links are equally valid names for one set of data, and the file's blocks are freed only when the last link is removed.

  • All hard links to a file are equal names for the same inode and the same data blocks.
  • Data is freed only when the inode's link count drops to zero, so deleting one link of many frees nothing.
  • Unlike symbolic links, hard links cannot cross filesystems and never become dangling references.

How a hard link works

On a Unix-style filesystem, a filename is just a directory entry that maps a name to an inode, the on-disk structure holding a file's metadata and pointers to its data blocks. A hard link creates a second name that references the very same inode, so both names are first-class and indistinguishable. There is no 'original' and 'copy'; they share one identity and one set of data blocks.

Each inode keeps a link count. Creating a hard link (for example with `ln target newname`) increments it; deleting a name decrements it. The filesystem reclaims the data blocks only when the link count reaches zero, which is why removing one of several hard links frees no space at all.

Hard link vs symbolic link

A symbolic link stores a path string that points at another name and resolves at access time, so it can cross filesystems and can dangle if the target is deleted. A hard link points directly at the inode, so it cannot cross filesystem boundaries and never dangles, the data survives as long as any link remains.

Because hard links share an inode, all links report the same size, the same content, and the same inode number (visible with `ls -i`). Most filesystems disallow hard-linking directories to avoid cycles.

Why it matters for duplicate detection

Two files that look like duplicates may actually be hard links to one inode, meaning they already share storage and deleting one recovers nothing. Naive duplicate scanners that compare only names, sizes, or even content will flag these as redundant copies and overstate recoverable space.

A careful cleaner like Cleanor treats files sharing an inode as a single physical object, so it does not double-count hard-linked data or promise space that a delete cannot return.

Related terms

Keep reading the reference.

Act on it

Guides and tools for this topic.