readlink -f: get the real path behind any symlink
Resolve symlinks and relative paths to a canonical absolute path on Linux with readlink -f.
Run readlink -f PATH to print the fully resolved absolute path, following every symlink component.
01Command
Command
$ readlink -f /usr/bin/python3 && readlink -f ./../link02What it does
Bare readlink prints only the immediate target of a symlink, which is often relative and can itself be another link. readlink -f canonicalizes the whole chain — expanding every symlink and collapsing ../ and ./ segments — which is what scripts need to locate their own real directory ($(dirname $(readlink -f "$0"))). Newer coreutils also offers realpath as a near synonym.
03Risk
!Warning: -f requires every path component to exist; use -e or -m if the final target may not exist yet.
04Undo
✓No undo needed — this command does not change persistent state.
05Sources
- realpath(3) — Linux manual pageEvidence: Documents the canonicalization that readlink -f performs: resolving symlinks and /./ /../ components
- readlink(1) — Arch Linux manualEvidence: -f, --canonicalize: canonicalize by following every symlink in every component; all components must exist
Last verified: 2026-09-17 · Category: Files & Folders