Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

5
  • 1
    What Unix are you running ps aux on? On OpenBSD and Ubuntu, ps aux does not show working directory. Commented Jul 28, 2018 at 7:09
  • @Kusalananda I was out last night when I posted my answer and wasn't able to test it. As a result, it seems that I forgot and I left off a part of it the command smacks head. Adding ww will make the columns wider and show as many columns as possible and adding f shows the hierarchy of the process. The questionner didn't specify which Unix/distro he's using and while I can't test it with every single one, I have confirmed that ps auxww works with CentOS 7.5, RHEL 7.5, Debian 9, and FreeBSD 11 although ps auxf doesn't show the hierarchy in FreeBSD 11. Commented Jul 28, 2018 at 13:08
  • @NasirRiley - ps auxww does not show the cwd on CentOS 7.5. ww stops ps from truncating output, which is useful for long process arguments, or when used with e (show environment) but doesn't otherwise add data. Compare ps auxe with ps auxwwe. But even that doesn't show current directory. eg $ ps auxwwe | grep httpd | tail -1 apache 29709 0.0 0.1 414980 7676 ? S Jul22 0:00 /usr/sbin/httpd -DFOREGROUND - there's no directory listed for that apache process. Commented Jul 28, 2018 at 13:48
  • @StephenHarris You are correct. I thought that by working directory that he meant where the command was running from. There isn't a portable way to do it with ps on its own so I've updated my answer. Commented Jul 28, 2018 at 16:36
  • lsof -d cwd seems to do the trick Commented Mar 3, 2021 at 15:35