Site icon New Generation Enterprise Linux

Supercharge `ps` Output with Custom `awk` Formatting

Quick Tip

Supercharge `ps` Output with Custom `awk` Formatting

Challenge: The default output of the `ps` command can be verbose and difficult to parse quickly for specific process information, especially when you need to extract particular columns or filter based on values.

The Solution: Leverage the power of `awk` to precisely format and filter the output of `ps`, giving you only the information you need.

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

Why it works: This command uses `ps aux` to list all running processes with detailed information. `awk` then processes this output line by line, printing only the specified fields: user, PID, CPU usage, and command name. You can easily adjust the field numbers (e.g., `$1`, `$2`) to display any column from `ps` output.

Pro-Tip: To sort the output by CPU usage in descending order, pipe the `awk` output to `sort -rnk3` (assuming CPU usage is the 3rd field).

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

0 0 votes
Article Rating
Exit mobile version