Home·Terminal commands

realpath

Files and directories

Usage

realpath [path]

Turns any path into one absolute path with symlinks and dots resolved; the macOS build is the BSD one, so GNU flags like --relative-to are absent.

Common flags

FlagMeaning
-qBSD and macOS: stay quiet when a path cannot be resolved
-eGNU: fail unless every component exists
-mGNU: never fail, even if nothing exists
-sGNU: do not expand symlinks
--relative-toGNU: print the answer relative to a directory

Examples

realpath ../src/./index.ts

Prints one absolute path with dots resolved.

realpath --relative-to=/var /var/log/nginx

Prints log/nginx (GNU only).

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 realpath do?

Turns any path into one absolute path with symlinks and dots resolved; the macOS build is the BSD one, so GNU flags like --relative-to are absent.

Q. How do I type it?

realpath [path] — square brackets mark the parts you can leave out.

Q. How many flags are worth knowing?

5 are listed here; the full set is in man realpath. This command sits under Files and directories.

Related commands

man page: man realpath