Symbolic links and hard links
In short: A symbolic link (symlink) is a shortcut pointing to a path. A hard link is a second name for the same file.
In more detail: A symlink stores only the target path as text. If the target is moved or deleted, the link points to nothing (“broken link”). A hard link points directly to the data and stays valid as long as at least one name exists.
In Depth
- Creating:
ln -s target linkname(symlink),ln target linkname(hard link). - Directories: Symlinks can point to folders and across file systems; hard links cannot.
- Security: Attackers use symlinks for path tricks, so check target paths before access (
realpath). - Use cases: Switching program versions (
current → release-42), placing configurations in one location. - Windows: Knows similar concepts as shortcuts, junctions and symlinks.
See also: Inodes