12

What is the difference between ps -aux and ps aux? I wonder it's more than a mere matter of syntax and "portability". Which one is better to use in Ubuntu?

Despite there are some similar question, I'm interested in this specific difference.

floatingpurr
  • 607
  • 2
  • 7
  • 15
  • 1
    @muru weirdddddddd :D I answered that it seems. Totally forgot about that one. But we both got 17 upvotes and I got 17 on this one. Must be the same 17 people >:-D – Rinzwind Apr 05 '18 at 06:23
  • @Rinzwind who knows... by the way, it looks you made a typo: did you mean "please use `ps aux`"? After all, the output of `ps -aux` is dependent on there being a user named `x`. – muru Apr 05 '18 at 06:28
  • @muru yeah I got confused myself >:-D – Rinzwind Apr 05 '18 at 06:33
  • @Rinzwind I'm sorry, but I still do not understand why you should use `ps aux`, that's the BSD flavor. – floatingpurr Apr 05 '18 at 09:18
  • Because Debian does it correctly ;-) – Rinzwind Apr 05 '18 at 09:21
  • Ok, pretty weird situation.. – floatingpurr Apr 05 '18 at 09:29
  • 1
    @floatingpurr because the -aux version will fail / behave differently depending on user 'x' existing or not. `ps -ef` is the correct equivalent using the dash syntax – mbrig Apr 06 '18 at 14:24

1 Answers1

19

BSD and AT&T developed incompatible versions of ps. The options without a leading dash are the BSD style while those with a leading dash are AT&T Unix style.

The ps man page has this to say too:

Note that "ps -aux" is distinct from "ps aux". The POSIX and UNIX standards require that "ps -aux" print all processes owned by a user named "x", as well as printing all processes that would be selected by the -a option. If the user named "x" does not exist, this "ps" may interpret the command as "ps aux" instead and print a warning. This behavior is intended to aid in transitioning old scripts and habits. It is fragile, subject to change, and thus should not be relied upon.

Linux opted to support both. ps -au{user} will error out if you provide a non-existing user. See:

$ ps -autest
error: user name does not exist

Usage:
 ps [options]

 Try 'ps --help <simple|list|output|threads|misc|all>'
  or 'ps --help <s|l|o|t|m|a>'
 for additional help text.

For more details see ps(1).

Ubuntu/Canonical opted to show an error. Debian opted to give the same output to both ps -aux and ps aux. All in all, pretty confusing. But as stated: this is/was to make scripts compatible. And you can use what you feel happy with.

Rinzwind
  • 293,910
  • 41
  • 570
  • 710
  • 1
    So I can use `ps -aux` but if the user `x` doesn't exist it falls back to a completely different meaning for those options? That is more confusing than if it just exited with an error. They should force an option to either use the BSD or Unix definition, conditional switching between option definitions based on an error case (non-existent user) seems crazy to me. It seems `ps -aux` should not be recommended. For people as confused as I am who want to stick with the Unix options, `ps -eF` provides almost the same information as `ps aux` (gives proc size instead of virtual size) – theferrit32 Apr 04 '18 at 17:37
  • 3
    Shouldn't that be "please do not use ps -aux" ? Or do you mean to try it and see what happens – mbrig Apr 04 '18 at 21:06
  • So, what is the verdict? – floatingpurr Apr 04 '18 at 23:01