18.5 realpath: Print the resolved file name.

The realpath command outputs a file’s canonicalized name, which is an absolute file name that contains neither unnecessary ‘/’ nor components that are ‘.’, ‘..’, or a symbolic link.

Synopsis:

realpath [option]... file...

By default, realpath succeeds if every file name component but the last names an existing directory. It ignores trailing slashes that are not also leading slashes.

The file name canonicalization functionality overlaps with that of the readlink command. This is the preferred command for canonicalization as it’s a more suitable and standard name. In addition this command supports relative file name processing functionality.

The program accepts the following options. Also see Common options.

-E
--canonicalize

Do not fail merely because the named file does not exist. Although this is the default behavior of GNU realpath, POSIX does not require this default, so portable applications should use an explicit -E.

-e
--canonicalize-existing

Fail if the named file does not exist. A trailing slash requires that the name 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

Symbolic links are resolved in the specified file names, but they are resolved after any subsequent ‘..’ components are processed.

-P
--physical

Symbolic links are resolved in the specified file names, and they are resolved before any subsequent ‘..’ components are processed. This is the default mode of operation.

-q
--quiet

Suppress diagnostic messages for specified file names.

--relative-to=dir

Print the resolved file names relative to the specified directory. This option honors the -m and -e options pertaining to file existence.

--relative-base=dir

Print the resolved file names as relative if the files are descendants of dir. Otherwise, print the resolved file names as absolute. This option honors the -m and -e options pertaining to file existence. For details about combining --relative-to and --relative-base, see Realpath usage examples.

-s
--strip
--no-symlinks

Do not resolve symbolic links. Only resolve references to ‘/./’, ‘/../’ and remove extra ‘/’ characters. When combined with the -m option, realpath operates only on the file name, and does not touch any actual file.

-z
--zero

Output a zero byte (ASCII NUL) at the end of each line, rather than a newline. This option enables other programs to parse the output even when that output would contain data with embedded newlines.

Exit status:

0 if all file names were printed without issue.
1 otherwise.