Skip to main content
>_ supraj.dev
TOPIC LINUX
Symlinks & Hard Links two names for one file
IN 10 SECONDS

A symlink is a pointer file referencing another file path (like a shortcut). A hard link is a duplicate directory entry pointing directly to the file's raw disk sectors (inode).

GOTCHA Deleting the target of a symlink leaves a dead dangling link. Deleting the target of a hard link keeps the data on disk until all hard links are removed.
HOW SYMLINKS VS HARD LINKS BEHAVE
01 Symlink read OS opens symlink, reads the path target string, and redirects to target file.
02 Hard link read OS maps hard link directory entry directly to the file's raw disk partition inode.
03 Target deleted if target is deleted, symlink breaks immediately, but hard link still opens the data.
04 Link limits hard links cannot span different filesystems or reference directories.
POKE IT YOURSELF
ln -s target.txt shortcut.txt — create a symbolic link
ln target.txt hardlink.txt — create a hard link