Site icon New Generation Enterprise Linux

Taming `ps`: Focused Process Info with `awk`

Quick Tip

Taming `ps`: Focused Process Info with `awk`

Challenge: The output of the ps command can be overwhelming, especially when trying to find specific information about running processes. You might want to quickly see a process’s PID, its CPU usage, and its command name, without all the extra columns.

The Solution: Leverage the power of awk to filter and format the output of ps.

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

Why it works: This command pipes the output of ps aux to awk. awk 'NR==1{print $1,$2,$3,$4,$11}' prints the header (User, PID, %CPU, %MEM, Command) from the first line. Then, NR>1{print $1,$2,$3,$4,$11}' prints the same columns for all subsequent lines, effectively giving you a cleaner, more focused view of your running processes.

Pro-Tip: You can easily change the column numbers in the awk command to display different information. For example, to also include the start time (column 9), you could use: ps aux | awk 'NR==1{print $1,$2,$3,$4,$9,$11} NR>1{print $1,$2,$3,$4,$9,$11}'

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

0 0 votes
Article Rating
Exit mobile version