realpath: print the resolved absolute pathname
realpath [OPTION]... FILE...
Options you will use
-e, --canonicalize-existing- All components of the path must exist.
-m, --canonicalize-missing- No path components need exist or be a directory.
-s, --strip, --no-symlinks- Don't expand symlinks: only tidy the path (., .., repeated /).
--relative-to=DIR- Print the resolved path relative to DIR.
--relative-base=DIR- Print absolute paths unless the path (and --relative-to) is below DIR.
-q, --quiet- Suppress most error messages.
-z, --zero- End each output line with NUL, not newline.
Examples
$ realpath --relative-to=. /var/log/syslogthe path to a file you know absolutely, as seen from where you are
$ realpath --relative-to=/etc/nginx /etc/ssl/certs../ssl/certs - handy for relative symlinks: ln -s "$(realpath --relative-to=DIR TARGET)" DIR/name
$ realpath -m /no/such/../dir/no/dir - tidy a path that does not exist (yet)
Gotchas
- Default (-E): every part but the last must exist. A relative path is relative to a DIRECTORY: --relative-to=. means "from where I am now".
Try realpath in a real terminal Free, in your browser - a real Ubuntu terminal to try it in, with missions that check your work.