Skip to main content
Learn how Linux file systems use hard links to let multiple directory entries point to the same underlying data. You’ll see how to create, inspect, and remove hard links without wasting disk space. Every file on a Linux filesystem (ext4, XFS, etc.) is represented by an inode. The inode stores metadata—permissions, timestamps, and pointers to data blocks on disk. The “Links” count in the stat output shows how many directory entries (hard links) reference that inode. Let’s simulate Aaron saving a photo of his dog:
Example output:
Each new file has one link by default. Copying files duplicates data and consumes extra space:
Hard links solve this by pointing two filenames to the same inode:
Now both entries share one set of data blocks.
Hard links only work on regular files within the same filesystem. See limitations below.
After creating the hard link, check the link count again:
Now Links: 2 confirms two directory entries point to the same inode.
  • If Aaron removes his entry:
  • Only when all links are removed does the filesystem reclaim the inode and free the data blocks:
You cannot:
  • Link directories (to prevent cycles in the filesystem tree).
  • Cross filesystem boundaries (e.g., SSD → external drive).
The image illustrates limitations and considerations of hardlinking, showing that hardlinks can only be created for files, not folders, and must be on the same filesystem.
Attempting to ln a file across different mounts will fail silently or return an error:
Permissions and ownership are stored in the inode itself. Changing them via any hard link affects all links:
Ensure users have the appropriate permissions in the target directory before creating a hard link.

Further Reading

Watch Video