realpath

Return resolved physical path.

Syntax
      realpath [-q] [path ...]

Key
   -q   warnings will not be printed when realpath(3) fails..

The realpath utility uses the realpath(3) function to resolve all symbolic links, extra ‘/’ characters and references to /./ and /../ in path.

If path is absent, the current working directory (‘.’) is assumed.

The realpath utility exits 0 on success, and >0 if an error occurs.

Examples

Show the physical path of the /dev/log directory silencing warnings if any:

$ realpath -q /dev/log
/var/run/log

Show the physical path of ~/:

$ realpath ~/
/Users/chenelo

Set the variable $BASE to the directory where a script is currently saved:

#!/bin/bash
BASE="$(dirname $(realpath $0))"

“A real decision is measured by the fact that you've taken a new action. If there's no action, you haven't truly decided” ~ Tony Robbins

Related macOS commands

Local man page: realpath - Command line help page on your local machine.
basename – Strip directory and suffix from filenames.
dirname – Convert a full pathname to just a path.


 
Copyright © 1999-2025 windevcluster.com
Some rights reserved