Site icon New Generation Enterprise Linux

Taming `ps` Output with Custom `awk` Formatting

Quick Tip

Taming `ps` Output with Custom `awk` Formatting

Challenge: The output of the `ps` command can be verbose and difficult to parse when you’re only interested in specific process details like PID, user, and command name.

The Solution: Leverage `awk` to filter and format the `ps` output to display only the essential columns you need.

ps aux | awk '{print $2, $1, $11}'

Why it works: `ps aux` provides a comprehensive snapshot of running processes. `awk ‘{print $2, $1, $11}’` then selects and prints the second column (PID), first column (USER), and eleventh column (COMMAND) from each line of the `ps` output, effectively cleaning up the display.

Pro-Tip: To sort the output by CPU usage (descending), pipe the result to `sort -rnk3` (e.g., ps aux | awk '{print $2, $1, $11, $3}' | sort -rnk4).

Linux Tips & Tricks | © ngelinux.com | 5/17/2026

0 0 votes
Article Rating
Exit mobile version