Quick Tip
Taming `ps`: Focused Process Info with `awk`
Challenge: The output of the `ps` command can be overwhelming, especially on busy systems. You often need to filter and sort through it to find specific processes or their resource usage.
The Solution: Leverage `awk` to precisely extract and format the information you need from `ps`. For example, to see the PID, user, and CPU usage of all processes sorted by CPU usage in descending order:
ps aux | awk 'NR==1 || $3 ~ /^[0-9]+(\.[0-9]+)?$/ { print $0 }' | sort -k3 -nr
Why it works: This command first lists all processes (`ps aux`). `awk` then filters out header lines and lines where the CPU usage column (field 3) is not a valid number, ensuring we only process relevant data. Finally, `sort -k3 -nr` sorts the output numerically in reverse order based on the CPU usage column.
Pro-Tip: You can easily adapt the `awk` command to select different fields (e.g., `print $1, $2, $4` for PID, USER, and MEM) and sort by different columns.
Linux Tips & Tricks | © ngelinux.com | 5/31/2026
