≡ Menu

Linux / Unix: pwdx Command Examples

pwdx command

I am new Linux and Unix system administrator. How do I find the current working directory of a process or server on Linux or Unix-like system using shell prompt?

On Linux and Solairs Unix you can use pwdx comamnd to display the current working directory of each process.

pwdx command details
DescriptionShow current working directory
of a process
Root privilegesYes
Estimated completion time1m
This command depends upon /proc/ file system to get a list of process-ids (PID). The pwdx command only available on Linux and Sun/Oracle Solaris Unix. If this command not available on your Unix-like system, try using combination of any one of the following command:

  1. lsof command
  2. ps command
  3. pgrep command


Print the current working directory of each process.


The basic syntax is as follows:

pwdx pid


pwdx pid1 pid2 pid3

pwdx command examples

In this example, find out the working directory of a process called lighttpd. First, run ps command to find out PID of a process called lighttpd:
$ ps aux | grep {process-name}
$ ps aux | grep lighttpd

You can skip ps and grep combo and use pgrep command as follows for the same purpose:
$ pgrep lighttpd
Sample outputs:


To display the current working directory of PID # 2225, enter:
$ sudo pwdx 2225
# pwdx 2225
Sample outputs:

2225: /

Using /proc/ file system to find out the current working directory of a process

You can run the following command to get the same information:

pgrep processNameHere
ls -d  /proc/$PID/cwd
## if pid is 1313, try ##
ls -d  /proc/1313/cwd

Finding jail directory

For security concern certain process run inside the jail (see chroot command for more information). Here is an example of named (BIND DNS server) process running inside the jail:
# pgrep named
# pwdx 1617
# ls -d /proc/1617/cwd

Sample outputs:
pwdx command demo
In this example, output indicate that named process has root directory at /var/cache/bind location.

pwdx command options

From the pwdx(1) command man page:

pidsState pid a process or processes.
-VDisplays version of program.
See also
CategoryList of Unix and Linux commands
File Managementcat
Network Utilitiesdighostip
Processes Managementbgchrootdisownfgjobskillkillallpwdxtimepidofpstree
User Informationgroupsidlastlastcommlognameuserswwhowhoamilidmembers

Tweet itFacebook itGoogle+ itPDF itFound an error/typo on this page?

{ 0 comments… add one }

Leave a Comment