Skip to content
TrySitePrice

Linux realpath: Find Absolute Pathname For Given Command or File

Best/Tutorial

The realpath command in Linux can be used to find the absolute pathname for a given command or file. Here's an example:

$ realpath /usr/bin/pythonrn/usr/bin/python

In this example, we're using realpath to find the absolute pathname for the python command located in the /usr/bin directory. The output shows that the absolute pathname for this command is /usr/bin/python.

realpath can also be used to find the absolute pathname for a file. Here's an example:

$ realpath myfile.txtrn/home/myuser/myfile.txt

In this example, we're using realpath to find the absolute pathname for a file named myfile.txt. The output shows that the absolute pathname for this file is /home/myuser/myfile.txt.

realpath can also handle relative paths, like this:

$ realpath ../mydir/myfile.txtrn/home/myuser/mydir/myfile.txt

In this example, we're using realpath to find the absolute pathname for a file named myfile.txt located in a directory named mydir that is one level up from the current directory. The output shows that the absolute pathname for this file is /home/myuser/mydir/myfile.txt.