How to retrieve absolute path given relative

nubme picture nubme · Nov 14, 2010 · Viewed 195.6k times · Source

Is there a command to retrieve the absolute path given the relative path?

For example I want $line to contain the absolute path of each file in dir ./etc/

find ./ -type f | while read line; do
   echo $line
done

Answer

epere4 picture epere4 · Feb 15, 2013

Try realpath.

~ $ sudo apt-get install realpath  # may already be installed
~ $ realpath .bashrc
/home/username/.bashrc

To avoid expanding symlinks, use realpath -s.

The answer comes from "bash/fish command to print absolute path to a file".