readlink on Linux: Resolve Symlinks and Real Paths

readlink command linux - custom-readlink-featured.png

readlink on Linux shows where a symlink actually points — essential for nginx sites-enabled chains, Java alternatives, and “wrong binary” mysteries when which and ls -l disagree.

Related: which,
stat,
lsblk.

Symlink target

Without -f, readlink prints only the immediate link text.

bashtarget
readlink /usr/bin/python3
readlink
target

Canonical path

readlink -f (GNU) resolves all components — fails on missing final target.

bashcanonical
readlink -f /etc/alternatives/python3
readlink -f
canonical

Broken links

Non-existent targets error — that is the signal in health checks.

bashcheck
for l in /etc/alternatives/*; do readlink -f "$l" 2>/dev/null || echo "broken: $l"; done | head
broken
check

Deploy scripts

Store real paths for systemd ExecStart to avoid PATH surprises.

WarningBusyBox readlink may lack -f — use realpath where available on minimal images.
ExecStart
systemd

Quick Reference

  • One hop: readlink path
  • Full path: readlink -f path
  • Breakage: stderr on missing target

Related tutorials

Diagrams are original illustrations by Gnome IT Solutions. Tutorial text © Gnome IT Solutions.