Site icon New Generation Enterprise Linux

Tame Your Processes: Focused `ps` Output with `awk`

Quick Tip

Tame Your Processes: Focused `ps` Output with `awk`

Challenge: The standard `ps aux` command can be overwhelming with too much information when you’re trying to quickly find specific process details like CPU or memory usage, or identify processes by a particular user.

The Solution: Combine `ps` with `awk` for precise control over the displayed columns.

ps aux | awk 'NR==1 || $1=="your_user" {print $1, $2, $3, $4, $11}'

Why it works: `awk` allows you to select specific fields (columns) from the output of `ps`. ‘NR==1’ ensures the header row is always printed, while ‘$1==”your_user”‘ filters for processes owned by ‘your_user’. The numbers following ‘$’ refer to the column number (e.g., $1 is USER, $2 is PID, $3 is %CPU, $4 is %MEM, $11 is COMMAND).

Pro-Tip: To sort processes by CPU usage, pipe the output to sort -rnk3 (where 3 is the column for %CPU). Example: ps aux | awk 'NR==1 || $1=="your_user" {print $1, $2, $3, $4, $11}' | sort -rnk3

Linux Tips & Tricks | © ngelinux.com | 6/29/2026

0 0 votes
Article Rating
Exit mobile version