简体   繁体   中英

how to get absolute path from relative path in command line

I run this command "httpd -d ./inst2 -k start" to boot Apache Server, and I can see this command line through "ps -ef | grep httpd". My question is if i don't know the absolute path, is there a way to get the absolute path of "./inst2"?

Thanks

You can try to GUESS what the absolute path is by examining the pseudo symbolic link /proc/PID/cwd where PID can be determined from the ps output: ls -l /proc/PID/cwd . But please note that it is just the current working directory and your path may be resolved against any other directory, so it is just a guess .

Another option, if your program opens some files using this relative path and in fact you need to determine the full path of such files, you can enumerate files currently open by some process using /proc/PID/fd pseudo directory: ls -l /proc/PID/fd . But, of course, the file can already be closed by the time of executing ls . And I don't know what it will show if the open file was moved to some other place.

To get the absolute path of a file/directory even you can execute following command on linux.

  1. find $HOME -type f -name " inst2 " (for file)
  2. find $HOME -type d -name " inst2 " (for directory)

this can give you absolute path for any file or directory. If the file is not in your home then use sudo in front of commands and replace $HOME by / .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM