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
CategoryProcesses Management
Difficulty levelEasy
Root privilegesYes
OS compatibilityLinux/Unix
Est. reading time2 minutes
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:


nixCraft: Privacy First, Reader Supported
  • nixCraft is a one-person operation. I create all the content myself, with no help from AI or ML. I keep the content accurate and up-to-date.
  • Your privacy is my top priority. I don’t track you, show you ads, or spam you with emails. Just pure content in the true spirit of Linux and FLOSS.
  • Fast and clean browsing experience. nixCraft is designed to be fast and easy to use. You won’t have to deal with pop-ups, ads, cookie banners, or other distractions.
  • Support independent content creators. nixCraft is a labor of love, and it’s only possible thanks to the support of our readers. If you enjoy the content, please support us on Patreon or share this page on social media or your blog. Every bit helps.

Join Patreon

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

Purpose

Print the current working directory of each process.

Syntax

The basic syntax is as follows:

pwdx pid

OR

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:

2225

To display the current working directory of PID # 2225, enter:
$ sudo pwdx 2225
OR
# 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 command man page:

Option Description
pids State pid a process or processes.
-V Displays version of program.
See also

Did you notice? 🧐

nixCraft is ad-free to protect your privacy and security. We rely on reader support to keep the site running. Please consider subscribing to us on Patreon or supporting us with a one-time support through PayPal or purchase official merchandise. Your support will help us cover the costs of hosting, CDN, DNS, and tutorial creation.

About the author: Vivek Gite is the founder of nixCraft, the oldest running blog about Linux and open source. He wrote more than 7k+ posts and helped numerous readers to master IT topics. Join the nixCraft community via RSS Feed or Email Newsletter.

🥺 Was this helpful? Please add a comment to show your appreciation or feedback.


0 comments… add one

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre> for code samples. Your comment will appear only after approval by the site admin.