Symlinks

Last Updated:

A symbolic link is a filesystem entry whose contents are a pathname to another file or directory.1

That makes it path-based indirection. A symlink does not duplicate the target’s contents, and it is not the same thing as a hard link. A hard link refers to the same underlying filesystem object; a symlink points to another name.1

Behavior

  • Deleting a symlink deletes the link, not the target.
  • Moving or deleting the target can leave a dangling link.
  • A symlink can point to a directory.
  • A symlink can cross filesystem boundaries.
  • A symlink target does not need to exist when the link is created.
  • Relative symlink targets are resolved from the link’s containing directory.

Most file access follows the link. cat link-to-file usually reads the target. Other operations work on the link itself: rm removes the link, readlink reads the stored path, and lstat stats the link rather than the target.1

ln -s

On Unix-like systems, ln creates links. With -s, it creates a symbolic link instead of a hard link.2

ln -s target-path link-path

The target path is stored as given. That is why relative links are portable only when the relationship between link and target stays the same.

Hard links and symlinks solve different problems.

Link typePoints toCan cross filesystemsCan dangle
hard linkunderlying file objectnono
symlinkpathname to another entryyesyes

Hard links are useful when multiple directory entries should name the same file object. Symlinks are useful when one canonical path should be reachable from another place or when the target may be a directory or live on another filesystem.

Traversal

Recursive tools need explicit symlink rules. The common convention is:

  • -P: physical walk; do not follow symlinks during traversal.
  • -H: follow command-line symlinks.
  • -L: logical walk; follow symlinks encountered during traversal.

The exact behavior still depends on the tool. rm -r symlink removes the link itself and does not recurse into the target directory.1

Uses

Symlinks are useful for compatibility paths, shared config files, generated content trees, and making one canonical directory appear in several places.

They are also maintenance-sensitive. If a build tool, deployment system, or backup program resolves symlinks differently than expected, the result can be a missing file, a duplicated tree, or writes landing in the wrong location.

Questions

  • Does this project prefer relative or absolute symlink targets?
  • Does the deploy target preserve symlinks or copy the referenced files?
  • Does the build tool report symlinks as links, resolved targets, or both?
  • Which commands in the workflow follow symlinks during recursive traversal?

Footnotes

  1. IEEE and The Open Group, “ln,” The Open Group Base Specifications Issue 8, https://pubs.opengroup.org/onlinepubs/9799919799/utilities/ln.html. Accessed 6 Jul. 2026.