Linux realpath: Find Absolute Pathname For Given Command or File

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/python
/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.txt
/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.txt
/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.

Leave a Comment