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. [donotprint]

pwdx command details
DescriptionShow current working directory
of a process
Root privilegesYes
Est. reading time1m
Table of contents
[/donotprint] 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:

Option Description
pids State pid a process or processes.
-V Displays version of program.
See also
  • pwdx(1) Linux/Unix command man page

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 0 comments... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
0 comments… add one

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum