Pcornel
Linux · Filesystem

Hard Links

Cheat sheet · https://pcornel.dk/topic.php?topic=2675

Back to the Topic

Answer

A hard link is another directory entry for the same inode. All names are equal; the data is freed only when the last link is removed and no process has it open.

Remember

Hard links cannot cross filesystems or point to directories. ls -l shows the link count; find -samefile finds all names. Editing through any name changes the same data.

First checks

  • ls -li <file> — inode and link count
  • find <dir> -samefile <file> — every name of the same inode
  • ls -ld <path> — owner, permissions and type
  • stat <path> — inode, links, size and timestamps
  • df -h <path> — filesystem and free space
  • findmnt <path> — which mount the path is on

Verify in this order

file created (link count 1) → ln adds another name for the same inode → each rm removes a name → data freed at 0 links

Where it usually breaks

First mismatch in hardware/block device → kernel driver/mapper/RAID/LVM → filesystem → mount namespace/options → path permissions/MAC → consumer I/O; preserve identity/native diagnostic/pre-state before mutation.

Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=2675

Confirmation

Confirm action

Continue?