realpath

Linux · Files · reference only

What it does

Converts a path into its canonical absolute form: it resolves ., .. and symbolic links.

Syntax

realpath [opciones] ruta...

Options and parameters

  • -e

    Requires every component to exist; otherwise it fails.

  • -m

    Does not require any component to exist.

  • -s

    Does not resolve symbolic links.

  • -q

    Suppresses error messages.

  • --relative-to=DIR

    Prints the path relative to that directory.

  • -z

    Ends each output line with a null character.

Usage examples

  • realpath ../notas.txt

    Returns the absolute path of notas.txt, one level above the current directory.

  • realpath -e /tmp/nada

    Fails because that path does not exist.

  • realpath --relative-to=/home/ana /home/ana/docs/a.txt

    Returns docs/a.txt, relative to /home/ana.

  • realpath -s enlace

    Returns the link's absolute path without following it to its target.

Notes and common mistakes

  • By default every component except the last must exist.

Related commands