Crisp answer: A hard link is another name pointing to the same inode (same data on disk). A soft link (symlink) is a separate file containing a path to the original.
Inodes:
Every file on a Linux filesystem is represented by an inode — a data structure storing metadata (permissions, ownership, timestamps, block locations) but NOT the filename. Filenames live in directories, which map names to inode numbers.
ls -li /etc/passwd
# 131073 -rw-r--r-- 1 root root 2847 Jan 1 /etc/passwd
# ^^^^ inode number
Hard link:
A hard link creates another directory entry pointing to the same inode. Both names refer to the same data. Deleting one doesn't delete the data — the data is only deleted when the link count reaches zero.
ln original.txt hardlink.txt
ls -li
# 131073 -rw-r--r-- 2 joyson joyson 100 original.txt
# 131073 -rw-r--r-- 2 joyson joyson 100 hardlink.txt
# ^ ^ link count = 2
# Limitations:
# - Cannot cross filesystem boundaries (must be same filesystem)
# - Cannot hard-link directories (would create loops)
Soft link (symlink):
A symlink is a separate file with its own inode containing a string — the path to the target.
ln -s /etc/nginx/nginx.conf nginx.conf
ls -la nginx.conf
# lrwxrwxrwx 1 joyson joyson 22 nginx.conf -> /etc/nginx/nginx.conf
# ^ ^^ symlink permissions are irrelevant — target's perms apply
# Characteristics:
# - Can cross filesystems
# - Can link directories
# - Breaks if the target is moved or deleted (dangling symlink)
# - ls -la shows -> target
Finding broken symlinks:
find /path -xtype l # Find broken (dangling) symlinks
find /path -type l -! -e {} # Alternative: symlinks with no target
Practical use cases:
| Use case | Link type |
|---|---|
| Multiple paths to the same binary | Hard link |
/usr/bin/python -> /usr/bin/python3 |
Symlink (cross-dir, easily updated) |
| Log directory pointing to different volume | Symlink |
| Kubernetes ConfigMap files in pod | Symlink (atomic updates) |
| SSL cert pointing to latest version | Symlink |
Kubernetes symlink detail: When Kubernetes mounts a ConfigMap as files, it creates symlinks so that updates to the ConfigMap are atomic — the symlink target changes atomically, so the app either sees the old or new version, never a partial write.
What to say in the interview:
"A hard link is another directory entry pointing to the same inode — same actual data on disk. Both names are equal; neither is the 'real' one. The file is only deleted when the last hard link is removed. A symlink is a separate file that contains a path string pointing to the target. Symlinks can cross filesystems and link to directories; hard links can't. The practical difference: if you move the target, a symlink breaks, a hard link doesn't. You see symlinks everywhere in Linux: python pointing to python3, /lib64 pointing to /lib, cert files pointing to the latest version."