Hard Links vs Soft Links

Linux has two types of links — hard links and symbolic (soft) links. They both look similar on the surface, but internally they work completely differently. Understanding them requires understanding inodes, which are how Linux actually tracks files.

The Key Insight: Files Are Not Their Names

What is the "real" identity of a file in Linux? The inode. An inode is a data structure that stores a file's metadata (size, permissions, timestamps, data block locations) and has a unique number. The filename is just a human-readable label that points to an inode — it's stored in the directory, not in the inode itself.
$ ls -i hello.txt 1234567 hello.txt ← 1234567 is the inode number $ stat hello.txt File: hello.txt Size: 42 Inode: 1234567 Links: 1 ...

When to Use Which

Hard LinkSymbolic Link
Points toInode directlyFile path (string)
Cross-filesystemNoYes
Link to directoriesNoYes
Breaks if original deletedNo (survives)Yes (dangling)
Common use caseBackup systems, package managersVersioning (python → python3.11), /etc/alternatives