brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: readlink -f follows every symlink and prints the real path

Linux
~/tips/tip-linux-readlink-f-resolve-symlink

readlink -f /usr/bin/python3

Resolves a chain of symlinks and prints the real absolute path of the target.

ls -l shows where a symlink points, but only one step at a time. When links point to links, I want the final answer.

readlink -f canonicalizes by following every symlink in every component of the name, recursively, and prints the absolute path:

readlink -f /usr/bin/python3
readlink -f ./current

It is handy to see which binary an alternatives link really leads to, or where a current release folder points today. A typical release layout has current pointing at a dated folder:

ln -sfn /mnt/user/appdata/<app>/releases/2026-11-28 /mnt/user/appdata/<app>/current
readlink -f /mnt/user/appdata/<app>/current

The second command prints the dated folder. Plain readlink without options would print only the direct target of that one link, which is the right choice when you want just one step.

There are two relatives. -e requires that every component exists, and -m has no requirement on whether components exist. With -f, all but the last component must exist, otherwise you get no output and a failing exit code.

The man page itself says realpath is a better command for canonicalization. In a new script I would reach for that, and keep readlink -f for habit at the prompt, where it is shorter to remember.

Further reading: readlink(1) manual page

More Linux tips a2query -m rewrite renice -n 10 -p 4242 cat config.yml | xsel -ib xvfb-run -a your-program --some-flag dpkg --get-selections > packages.txt All Linux tips (261) All topics

Link