ln command.
Links let you reference the same file data from multiple directory entries without duplicating the data on disk. Understanding links helps you manage files, backups, and filesystem layout safely.
Conceptual analogy
- Symbolic link (symlink): like a signpost that stores a path to a building. If the building is removed or moved, the signpost points to nothing (a dangling link).
- Hard link: like two doors leading into the same room. Both directory entries access the exact same data. Removing one door does not remove the room.
Inodes — a brief technical note
- An inode is a filesystem structure that stores metadata about a file (permissions, owner, timestamps) and pointers to the file’s data blocks.
- A hard link creates another directory entry that points to the same inode number. Both names reference one inode and therefore the same content.
- A symbolic link is a separate filesystem object (with its own inode) that stores a pathname that refers to the target file or directory.
Hard links cannot cross filesystem boundaries and, on most systems, you cannot create hard links to directories because that can create filesystem cycles and confuse tools that traverse the directory tree. Symbolic links can point to files or directories, and can cross filesystems.
When to use which
- Use a hard link when you need another name that references the exact same content on the same filesystem (for example, duplicate names without duplicating data).
- Use a symbolic link when you need to reference files or directories across filesystems or when you need links to directories. Symlinks are also useful for pointing to versioned targets, e.g.,
current -> release-2026.10.
Quick demo — create links and observe behavior
Follow these steps in a terminal to see hard and symbolic links in action. The commands are shown with a sample prompt to illustrate context; adapt them to your system. Step-by-step:Comparison table: hard link vs symbolic link
Summary
- Hard links add additional directory entries that reference the same inode; they are useful when you want multiple names for the same data on the same filesystem.
- Symbolic links are separate filesystem objects that store a path to the target and can point to files or directories across filesystems.
- Removing a filename that had hard links does not remove the data until all hard links are removed. Removing the target of a symlink makes the symlink dangling.
- Most systems disallow creating hard links to directories to prevent filesystem cycles and traversal issues.