readlink
Files and directories
Usage
readlink -f [path]Prints what a symlink points to, one hop only unless you add -f; on a file that is not a link it prints nothing and exits with an error.
Common flags
| Flag | Meaning |
|---|---|
| -f | Resolve every symlink and print the final absolute path |
| -n | Do not print a trailing newline |
| -e | GNU: like -f but fail if the path does not exist |
| -m | GNU: like -f but never fail |
Examples
readlink /usr/local/bin/nodePrints the one target the link points at.
readlink -f "$0"Resolves a script to its real location.
Moving, deleting and finding. Some of these do not ask twice, which is why -i becomes a habit.
How to read this
- Square brackets [ ] mark a part you may leave out.
- An ellipsis … means you can list more than one.
- Flags are case-sensitive — in some commands -r and -R do different things.
Questions
Q. What does readlink do?
Prints what a symlink points to, one hop only unless you add -f; on a file that is not a link it prints nothing and exits with an error.
Q. How do I type it?
readlink -f [path] — square brackets mark the parts you can leave out.
Q. How many flags are worth knowing?
4 are listed here; the full set is in man readlink. This command sits under Files and directories.
Related commands
man page: man readlink