The Computer Oracle

Is "ps -u" Really a Bad Syntax?

--------------------------------------------------
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
and get $2,000 discount on your first invoice
--------------------------------------------------

Take control of your privacy with Proton's trusted, Swiss-based, secure services.
Choose what you need and safeguard your digital life:
Mail: https://go.getproton.me/SH1CU
VPN: https://go.getproton.me/SH1DI
Password Manager: https://go.getproton.me/SH1DJ
Drive: https://go.getproton.me/SH1CT


Music by Eric Matyas
https://www.soundimage.org
Track title: Quiet Intelligence

--

Chapters
00:00 Is &Quot;Ps -U&Quot; Really A Bad Syntax?
00:44 Accepted Answer Score 130
01:30 Answer 2 Score 83
02:35 Thank you

--

Full question
https://superuser.com/questions/825964/i...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#linux #shell #ps

#avk47



ACCEPTED ANSWER

Score 130


The correct syntax, which returns the same output, would be:

ps u

There is a good reason why modern syntax for ps is a mess. Historically, there were two incompatible version of ps. Options with a leading dash were inherited from the AT&T Unix version of ps. Options without a leading dash were inherited from BSD. The version of ps that Linux distributions generally use is GNU which has merged both sets of options together, as well as added its own set of options that start with a leading double-dash.

Thus, ps u is BSD-style and ps -u $USER is AT&T-style. The fact that GNU ps allows you to run ps -u and, other than the warning, get the same output as ps u shows that GNU is attempting to make the best of a bad situation.




ANSWER 2

Score 83


The ps command historically had wildly different syntax in BSD and System V Unix.

  • In BSD ps, the u option (no dash) takes no parameter and shows the "user-oriented output" with the additional columns.

  • In SunOS ps, the -u option (with dash) takes a username as parameter and only includes processes owned by that user, but without changing the display format.

(As another very common example, BSD e means "show environment", while SunOS -e means "show everyone's processes".)

Linux procps ps tries to support both styles. So if you use the 'dash' option -u, it will expect it to be the SunOS "filter this user" option, not the extended columns option. The two are confused frequently enough, however, that procps tries to Do What You Meant – if the username is missing, it'll assume you gave it a BSD option but used SunOS syntax.

(There were in fact so many different variants of ps that the procps has an actual table of "personalities" to force ambiguous behavior to be interpreted as one style or another or yet another – in addition to knobs like "UNIX95", "CMD_ENV", "_XPG", "I_WANT_A_BROKEN_PS"...)