Streamline `ps` Output with Custom `awk` Formatting

Quick Tip

Streamline `ps` Output with Custom `awk` Formatting

Challenge: The default output of the `ps` command can be verbose and difficult to parse for specific process information, especially when dealing with many running processes.

The Solution: Leverage `awk` to filter and format the output of `ps` to display only the columns you need, sorted by CPU or memory usage.

ps aux | awk 'NR==1{print $0}; NR>1{if ($3 > 5.0) print $0}' | sort -k3 -rn

Why it works: This command uses `ps aux` to list all processes with detailed information. `awk` then prints the header line (`NR==1`) and any subsequent line (`NR>1`) where the CPU utilization (the 3rd column, `$3`) is greater than 5.0%. Finally, `sort -k3 -rn` sorts the results numerically in reverse order based on the CPU utilization column.

Pro-Tip: To sort by memory usage instead, replace `-k3 -rn` with `-k4 -rn` (assuming memory is the 4th column in `ps aux` output) and adjust the `awk` condition accordingly if needed.

Linux Tips & Tricks | © ngelinux.com | 4/27/2026

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments