Taming `ps` Output with Custom `awk` Formatting

Quick Tip

Taming `ps` Output with Custom `awk` Formatting

Challenge: The default output of the `ps` command can be verbose and difficult to parse when you need specific process information quickly. Often, you want to see just a few key details like PID, CPU usage, memory usage, and the command itself.

The Solution: Leverage `awk` to filter and format the output of `ps` to display only the columns you need.

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

Why it works: The `ps aux` command lists all running processes in a detailed format. `awk` then processes this output line by line, and the `'{print $2, $3, $4, $11}’` part tells `awk` to print the 2nd (PID), 3rd (%CPU), 4th (%MEM), and 11th (COMMAND) fields of each line.

Pro-Tip: You can customize the fields to display by changing the numbers after the ‘$’ symbol. For example, `ps aux | awk ‘{print $1, $2, $NF}’` will show the USER, PID, and the full COMMAND (using `$NF` for the last field).

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