What is the difference between hard links and soft links?

Answer

Both create references to files in Unix file systems, but they work at different levels: Hard link: a directory entry that points directly to the same inode (file data) as another directory entry. Multiple filenames can reference the same inode (same file data). ln original.txt hardlink.txt # Create hard link ls -i original.txt hardlink.txt # Same inode number! # 12345 original.txt; 12345 hardlink.txt. Characteristics: both names are equal — no "original" and "link"; deleting one name doesn't delete the file (inode deleted only when link count = 0); inode stores the link count; can't cross filesystem boundaries (inode numbers only unique per filesystem); can't link directories (would break the tree structure); file accessible by any of its hard link names even if others deleted. Soft link (symbolic link, symlink): a special file that contains a PATH (text) to another file or directory. Like a shortcut. ln -s original.txt symlink.txt # Create symbolic link ls -la symlink.txt # lrwxr-xr-x symlink.txt -> original.txt. Characteristics: symlink has its own inode; points to path, not inode; if target is deleted → dangling symlink (broken link); can cross filesystem boundaries; can link directories; path can be absolute or relative; can create circular symlinks. When to use which: hard links: when you need multiple equal-access paths to the same file content; symlinks: directories, across filesystems, when "pointing to" something is the intent (shortcuts, versioning: libpython.so → libpython.so.3.11).