Find Canonical Path with readlink
The readlink utility resolves symlinks and prints the canonical absolute path of a file. It’s the standard tool on Debian-based systems for determining what a symlink actually points to.
Core options
| Option | Behavior |
|---|---|
-f, --canonicalize | Follow every symlink recursively; all but the last component must exist |
-e, --canonicalize-existing | Follow every symlink recursively; all components must exist |
-m, --canonicalize-missing | Follow symlinks; no requirements on component existence |
Examples
# Resolve a symlink chain to its final target
readlink -f /usr/bin/python
# Require every component to exist (fails on broken symlinks)
readlink -e ./some-link
# Resolve even if the final target doesn't exist
readlink -m ./some-linkCaveats
readlinkfollows symlinks, so it is not suitable when you need to know the link itself rather than its target.- For a pure “print the resolved path” interface,
realpath(from coreutils) provides similar functionality with a slightly different flag layout. Seerealpath(1)for details.
Sources
Related: ssh, linux-reconnaissance-commands