Symlinks and Hardlinks: What They Solve and When to Use Them
Learn the difference between symbolic and hard links, what they cost, and when each is the right tool.
Netbay Engineering
Netbay Engineering
On this page
Links are references to files that let you reach the same data from multiple paths. Linux offers two kinds: hard links, which are additional names for the same inode and data, and symbolic links (symlinks), which are pointers to a path. Each solves a different problem, and choosing the wrong one quietly breaks deployments.
Hard Links: Multiple Names, One File
A hard link is another directory entry pointing to the same inode. The data exists once, and the file is only removed when the last hard link is deleted. To create one:
ln file.txt hardlink.txt
ln /data/current.log /data/first_run.logBoth names now reference identical content. Because they share the same inode, edits to either name are visible through the other. Deleting one link does not delete the data as long as another link exists.
The constraints of hard links matter:
- They cannot cross filesystems. You cannot hard link a file on one disk or partition to another.
- You cannot hard link a directory (without root and special options), because that would create cycles in the filesystem.
- Hard links are invisible in a directory listing as separate files; ls -li shows the same inode number.
Symbolic Links: Pointers to Paths
A symbolic link stores the path to another file or directory. Create one with the -s flag:
ln -s /var/www/app/current app-latest
ln -s /usr/local/nginx/conf/nginx.conf /etc/nginx/nginx.confThe symlink is a small separate inode containing the target path. It can cross filesystems, point to directories, and even point to another symlink. If the target is removed or moved, the symlink becomes dangling, meaning it points to a path that no longer exists.
Symlinks are the standard tool for versioned deploys. The classic pattern keeps a current symlink that points to the latest release:
ln -s /var/www/app/releases/2026-08-01 /var/www/app/currentPoint the symlink at a new release to switch versions atomically. The web server resolves current to the new directory with no downtime.
Comparing the Two
| Property | Hard link | Symlink | |---|---|---| | References | same inode | a path string | | Cross-filesystem | no | yes | | Directory target | not allowed | yes | | Survives target rename | depends | breaks | | Shown as separate file | no | yes (l) |
This table is the decision rule. If you need a stable reference that must work across the whole system and point to directories, use a symlink. If you need two names for the exact same data on the same filesystem, a hard link works, but in practice symlinks cover nearly every real need.
Practical Examples
Inspect links and their targets:
ls -l
ls -la /etc/rc*.d
readlink /var/www/app/current
find . -type l -lsls -la /etc/rc*.d shows a set of symlinks. readlink prints the target of a symlink. find . -type l -ls lists every symlink in a tree, useful for auditing a deployment.
To follow a symlink while working, the -L flag in many tools means follow links, while -P (default) means do not:
du -shL /var/www/app/current
find -L /etc -maxdepth 2 -type fTakeaway
Symlinks are the go-to tool for pointing at a specific path, especially across filesystems and for directories, while hard links are a niche option for the same filesystem. Use symlinks for release pointers and config conveniences. Build a release-pointer workflow on a Netbay Linux VPS at netbayhosts.in.
Keep reading
Follow along on a real VPS
Deploy Linux in under 60 seconds
These guides are written against Ubuntu, Debian, and RHEL-family images — the same ones on NetBay.
Deploy an instance