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 output of the ps command can be overwhelming, showing a multitude of processes with more information than you often need. It’s hard to quickly find specific process details.

The Solution: Use awk to filter and format the ps output to display only the columns you’re interested in.

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

Why it works: ps aux lists all running processes with user, CPU, memory, and command details. awk then processes this output line by line, printing only the specified fields (User, PID, %CPU, %MEM, and Command, respectively, based on the typical output of ps aux). You can adjust the numbers to select different fields.

Pro-Tip: To sort processes by CPU usage, pipe the output to sort -rnk3 (for descending numerical order on the 3rd column, which is %CPU in this example): ps aux | awk '{print $1, $2, $3, $4, $11}' | sort -rnk3

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

0 0 votes
Article Rating
Exit mobile version