Linux·5 min read·

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.

NB

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.

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:

bash
ln file.txt hardlink.txt
ln /data/current.log /data/first_run.log

Both 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.

A symbolic link stores the path to another file or directory. Create one with the -s flag:

bash
ln -s /var/www/app/current app-latest
ln -s /usr/local/nginx/conf/nginx.conf /etc/nginx/nginx.conf

The 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:

bash
ln -s /var/www/app/releases/2026-08-01 /var/www/app/current

Point 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:

bash
ls -l
ls -la /etc/rc*.d
readlink /var/www/app/current
find . -type l -ls

ls -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:

bash
du -shL /var/www/app/current
find -L /etc -maxdepth 2 -type f
Hard Links vs Symlinks hard link same inode, extra name same filesystem only no directories symlink points to a path string crosses filesystems targets directories release pointer pattern current -> releases/2026-08-01 atomically switch version ln -s new release current rule: use symlinks for pointers; hard links only inside one filesystem

Takeaway

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