Random Musings

Sporadic thoughts on tech, economics, business, finance and trading

ps command with dash and no-dash options

,

The ps command in Linux has two main styles for options: dash-options and no-dash-options, each adhering to different standards:

Dash-Options (e.g., -e, -f)

  • POSIX-compliant.
  • Options are preceded by a single dash (-).
  • Example: ps -e shows all processes.

No-Dash-Options (e.g., aux)

  • BSD-style syntax.
  • Options are not preceded by a dash.
  • Example: ps aux shows all processes with additional user and memory details.

Key Difference

  • Dash-options often require options to be combined or separated explicitly (-ef).
  • No-dash-options are generally more concise but less portable across UNIX variants.

Can I use ps -aux?

You can use ps -aux, but it is not technically correct and may produce unintended results:

  • -a, -u, and x are BSD-style options. They should be used without a dash, as in ps aux.
  • Using -aux invokes POSIX-style syntax, which may cause ps to interpret -u as an invalid user name depending on the system.

Correct Usage:

  • For BSD-style: ps aux
  • For POSIX-style: ps -e or ps -ef

It’s recommended to follow the correct style for clarity and portability.

Can you make an extensive list of ps with dash and no-dash options

Here’s an extensive list of common ps options categorized by dash (-) and no-dash usage styles:


With Dash (-): POSIX Style

OptionDescription
-aShow processes from all users (except session leaders).
-eDisplay all processes. Equivalent to -A.
-fFull-format listing, including user, PID, PPID, start time, and command.
-lLong-format listing.
-u <user>Display processes for a specific user.
-xInclude processes without a controlling terminal.
-p <pid>Display specific processes by their process IDs (PIDs).
-o <fields>Specify output format by selecting fields (e.g., PID, %CPU, %MEM).
-HShow processes in a hierarchical tree view.
--forestASCII-art process tree for visualizing relationships.

Without Dash: BSD Style

OptionDescription
aShow all processes for all users (interactive and non-interactive).
xInclude processes without a controlling terminal.
uDisplay user-oriented output format.
axShow all processes regardless of terminal association.
auxDisplay all processes with detailed information (user, CPU, memory usage).

Key Differences

  1. Dash Style (-): Follows POSIX conventions; options can be combined (e.g., -ef) or written separately.
  2. No-Dash Style: Follows BSD conventions; options are written together as a single string (e.g., aux).

Example Comparisons

  • ps -e (POSIX): Display all processes.
  • ps ax (BSD): Equivalent to ps -e, but shows all processes using BSD style.

For consistent cross-platform usage, POSIX style (ps -e, ps -f) is preferred, as not all systems support BSD syntax.