Two ways one file lives in two places
Unix lets a single file appear at multiple paths. There are two mechanisms with very different semantics:
- Hard link — a second name pointing to the same inode. Both names are equal; deleting one leaves the data alive as long as another name exists. Cannot cross filesystems.
- Symbolic link (symlink) — a small file whose content is a path. The OS follows it transparently. If the target moves or is deleted, the symlink dangles.
Creating links
ln source link— hard link.ln -s source link— symbolic link. You'll use this 99% of the time.
If you forget -s, you get a hard link silently. Most developers always type -s reflexively.
Recognising links
ls -l shows symlinks with an arrow: link -> /target/path. Hard links look identical to regular files; ls -i shows the inode number, and two hard links share one. stat link tells you the truth either way.
When each is the right tool
- Symlink — the default. Cross-filesystem, points to a path, can target directories. Used by Homebrew, dotfile managers, package managers.
- Hard link — when you want two stable references to the same data, in the same filesystem, with no "target" relationship. Time Machine uses hard links to share unchanged files between snapshots cheaply.