# info > realpath

---
type: CommandReference
command: realpath
mode: info
section: 
source: info
---

## Quick Reference

- `realpath FILE...` — print absolute canonical path of each FILE, resolving symlinks and `..` components
- `realpath -m FILE...` — canonicalize even if path components missing
- `realpath --relative-to=DIR FILE...` — print resolved paths relative to DIR
- `realpath --relative-base=DIR FILE...` — print relative paths if below DIR, else absolute
- `realpath -s FILE...` — only resolve `./`, `../`, and extra `/`; do not resolve symlinks

## Name

`realpath` — print the resolved file name, expanding all symbolic links and resolving references to `./`, `../`, and extra `/` characters.

## Synopsis

realpath [OPTION]... FILE...
## Options

- `-e`, `--canonicalize-existing` — ensure all components of the specified files exist. If any component is missing or unavailable, output a diagnostic (unless `-q` is given) and exit with nonzero exit code. A trailing slash requires the name to resolve to a directory.
- `-m`, `--canonicalize-missing` — if any component of a specified file name is missing or unavailable, treat it as a directory.
- `-L`, `--logical` — resolve symlinks after processing any subsequent `..` components.
- `-P`, `--physical` — resolve symlinks before processing any subsequent `..` components. This is the default.
- `-q`, `--quiet` — suppress diagnostic messages for specified file names.
- `--relative-to=DIR` — print the resolved file names relative to the specified directory. Honors `-m` and `-e`.
- `--relative-base=DIR` — print the resolved file names as relative if the files are descendants of DIR; otherwise print as absolute. Honors `-m` and `-e`.
- `-s`, `--strip`, `--no-symlinks` — do not resolve symbolic links; only resolve `./`, `../`, and remove extra `/`. Combined with `-m`, operates only on the file name without touching any actual file.
- `-z`, `--zero` — output a zero byte (ASCII NUL) at the end of each line instead of a newline.

## Examples

shell
# Default absolute path resolution
cd /home/user
realpath /usr/bin/sort /tmp/foo /usr/share/dict/words 1.txt
# ⇒ /usr/bin/sort
# ⇒ /tmp/foo
# ⇒ /usr/share/dict/american-english
# ⇒ /home/user/1.txt
shell
# Relative to a directory
realpath --relative-to=/usr/bin \
         /usr/bin/sort /tmp/foo /usr/share/dict/words 1.txt
# ⇒ sort
# ⇒ ../../tmp/foo
# ⇒ ../share/dict/american-english
# ⇒ ../../home/user/1.txt
shell
# Relative base: print relative only if below base
realpath --relative-base=/usr \
         /usr/bin/sort /tmp/foo /usr/share/dict/words 1.txt
# ⇒ bin/sort
# ⇒ /tmp/foo
# ⇒ share/dict/american-english
# ⇒ /home/user/1.txt
shell
# Combine --relative-to and --relative-base
realpath --relative-to=/usr/bin --relative-base=/usr \
         /usr/bin/sort /tmp/foo /usr/share/dict/words 1.txt
# ⇒ sort
# ⇒ /tmp/foo
# ⇒ ../share/dict/american-english
# ⇒ /home/user/1.txt
## See Also

- `readlink` — similar canonicalization functionality
- [Common options](https://www.gnu.org/software/coreutils/manual/html_node/Common-options.html) for coreutils

## Exit Codes

- `0` — all file names were printed without issue.
- `1` — otherwise.