Tame `ps` Output with Custom `awk` Formatting

Quick Tip

Tame `ps` Output with Custom `awk` Formatting

Challenge: The standard `ps` command can be overwhelming with too much information, making it hard to quickly find the exact process details you need. You often need specific fields like PID, CPU usage, and command name.

The Solution: Use `awk` with `ps` to select and format only the columns you’re interested in.

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

Why it works: This command first lists all running processes with `ps aux`. Then, `awk` processes this output line by line, printing only the specified fields (username, PID, %CPU, %MEM, and command) which are typically columns 1, 2, 3, 4, and 11 respectively.

Pro-Tip: For a more readable output, you can add headers using `echo` and `awk ‘NR==1{print $1,$2,$3,$4,$11}’`. So the full command would be: echo "USER PID %CPU %MEM COMMAND"; ps aux | awk '{print $1, $2, $3, $4, $11}' | tail -n +2

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

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments