readlink — Show symlink targets
Linux / File and disk management / readlink.html
Prints the target of a symlink, with -f resolving the full path.
Basic Information
| Command Name | readlink |
|---|---|
| One-line Introduction | Prints the target of a symlink, with -f resolving the full path. |
| Provided by | GNU coreutils (installed by default on all Linux distributions) |
| Official Documentation | https://man7.org/linux/man-pages/man1/readlink.1.html |
| Supported Operating Systems | Linux, macOS, BSD, WSL |
| Installation Status | Installed by default (no separate installation needed) |
| Category | Linux file and disk management (tags: symlink, path, link) |
What is this command?
readlink reads a symlink and prints its target. With -f it resolves every intermediate link into an absolute path.
It resembles realpath, but by default it shows the link target string as stored.
What problems does it solve?
- You need to see what a link points to
- A script must resolve its own real path
- You need the final target of a link chain
- You are testing whether a path is a link
Key features
Print the target
Shows the stored target string.
- When to use: You inspect link structure
- What you get: The target path string
- Limitations: Relative links appear as relative paths.
Resolve fully
-f follows all links to an absolute path.
- When to use: You need the exact script location
- What you get: A resolved absolute path
- Limitations: A missing final component causes failure.
Normalize only
-m normalizes even if components do not exist.
- When to use: You handle paths not yet created
- What you get: A normalized path
- Limitations: It does not verify actual links.
Installation and usage
Check whether it is installed
readlink --version
sudo apt install coreutils # Debian/Ubuntu sudo dnf install coreutils # Fedora
Real-world examples
Inspect a link
Print the target of the link.
readlink /usr/bin/awk
Real script path
Get the real file path even via a symlink.
SCRIPT=$(readlink -f "$0")
echo "$SCRIPT"
Normalize a path
Normalize even when the path does not exist.
readlink -m ./build/../dist/app.tar.gz