I am running a simulation that is commanded to begin at some directory, but don't remember from which directory I commanded the simulation. I'm using python for running the simulation, so

ps aux | grep PID

only shows where the executing program is located. (/usr/bin/python). However, I want to know where the command is operated from the very initial point, where the file I'm running is located.

I would greatly appreciate any helpful comments!

Thanks :)


Perhaps you'll want to use the history command to see which command you actually used?


To see the path of the python script, you can normally see it with ps (using the w, wide, option if needed):

~% ps ugxw | grep python
romano    2136  0.0  0.2  10524  4132 ?        S    09:13   0:00 python /home/romano/software/wallpap/bg_slideshow.py
romano    5839  0.0  0.0   4440   832 pts/1    S+   10:00   0:00 grep python

For example, process 2136 is the script /home/romano/software/wallpap/bg_slideshow.py. If you want to know which is the working directory of the process, do

~% ls -l /proc/2136/cwd
lrwxrwxrwx 1 romano romano 0 Nov 11 10:04 /proc/2136/cwd -> /home/romano

The process is running with /home/romano as its current directory.

In the file /proc/2136/cmdline there is the full command line specification --- the same you see in ps, with the commands and argument separated by 0-valued bytes (to preserve the spaces). You can see it on your terminal with

% cat /proc/2136/cmdline | tr "\0" " "
python /home/romano/software/wallpap/bg_slideshow.py % 

where "tr" prints a space for each "nul" character found. (the spurious % at the end is due to the file not ending with a newline char).

The /proc filesystem is a really useful tool --- the full documentation is a bit "hard" but it's often useful to have a link to it: https://www.kernel.org/doc/Documentation/filesystems/proc.txt


Use the which command. For example, which ifconfig outputs the location of the ifconfig command.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.