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
| Flag | Meaning |
|---|---|
| -q | BSD and macOS: stay quiet when a path cannot be resolved |
| -e | GNU: fail unless every component exists |
| -m | GNU: never fail, even if nothing exists |
| -s | GNU: do not expand symlinks |
| --relative-to | GNU: print the answer relative to a directory |
Examples
realpath ../src/./index.tsPrints one absolute path with dots resolved.
realpath --relative-to=/var /var/log/nginxPrints 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