UNIX Shell: Find Out Real Path Of File ( Directory )
Q. Some of my programs and scripts needs a real path and not a a symbolic link. How to I determine a real path of any directory under Linux / UNIX operating systems? How do I remove references to /./, /../ and extra '/' character in path?
A. To get physical path use realpath command. The realpath command uses the realpath() function to resolve all symbolic links, extra / characters and references to /./ and /../ in path. This is useful for shell scripting and security related applications.
realpath examples
Resolve symbolic link:
$ realpath /home
Sample output:
/usr/home
Remove characters:
$ realpath /etc//apache/.
$ realpath ./foo
$ realpath /../some/where///./../path/
realpath includes with many distro and UNIX operating system such as FreeBSD. To install realpath under Debian / Ubuntu Linux, enter:
$ sudo apt-get install realpath
readlink command
Please note that mostly the same functionality is provided by the -f option of the readlink command:
$ readlink -f /home
Further readings:
- man pages readlink, realpath
E-mail
Print
Can't find an answer to your question? Contact us
Related Other Helpful FAQs:
- Linux Find Out CPU Support 36-bit Physical Addressing Or Not
- Linux find out what process are eating all memory and time allocated to process
- Locate files on linux, FreeBSD and UNIX system
- Find files that do not have any owners or do not belong to any user under Linux/UNIX
- Linux / UNIX: Command not found error and how do I get rid of it?
Discussion on This FAQ
Leave a Reply
We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!
Tags: FreeBSD, physical path, readlink command, realpath command, scripts, shell scripting, symbolic link, ubuntu, unix operating system, unix operating systems



October 23rd, 2008 at 9:08 pm
I cant’t find realpath in CentOS. Coud you address me?
October 23rd, 2008 at 9:51 pm
Use readlink -f /path/to/file/or/dir command under RHEL / CentOS.
October 23rd, 2008 at 10:07 pm
Thanks!!!
October 24th, 2008 at 6:19 am
why you dont use the command
pwd -P
comes out of the box…