Used to display the current working directory of the specified process
pwdx [process ID]
In the following example, use the ps
command to view the information of the nginx
process, and then use the pwdx
command to query the current working directory of the process with process ID 5678
.
$ ps -ef | grep nginx
# root 1234 1 0 10:00 ? 00:00:00 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
# www-data 5678 1234 0 10:01 ? 00:00:00 nginx: worker process
$ pwdx 5678
# 5678: /var/www/html
View the working directory of the current process:
$ pwdx $$
View the working directory of a specified process:
$ pwdx 1234
View the working directories of multiple processes in batches:
$ ps aux | awk '{print $2}' | xargs pwdx
Combined with other commands, view the working directory and command line of a process:
$ ps -p 1234 -o cmd | tail -n 1 | awk '{print $1}' | xargs pwdx
View the working directories of all processes:
$ ps -eo pid | xargs pwdx