Home·Terminal commands

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

FlagMeaning
-fResolve every symlink and print the final absolute path
-nDo not print a trailing newline
-eGNU: like -f but fail if the path does not exist
-mGNU: like -f but never fail

Examples

readlink /usr/local/bin/node

Prints 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