100 Useful Command-Line Utilities

by Oliver; 2014

32. readlink

readlink provides a way to get the absolute path of a directory.

Get the absolute path of the directory mydir:
$ readlink -m mydir
Get the absolute path of the cwd:
$ readlink -m .
Note this is different than:
$ pwd
because I'm using the term absolute path to express not only that the path is not a relative path, but also to denote that it's free of symbolic links. So if we have the link discussed above:
~/MYLINK --> /some/long/and/complicated/path/to/an/often/used/directory
then:
$ cd ~/MYLINK
$ readlink -m . 
/some/long/and/complicated/path/to/an/often/used/directory
One profound annoyance: readlink doesn't work the same way on Mac unix (Darwin). To get the proper one, you need to download the GNU coreutils.

<PREV   NEXT>