Site icon New Generation Enterprise Linux

Master `ps` Output with Custom `awk` Formatting

Quick Tip

Master `ps` Output with Custom `awk` Formatting

Challenge: The default output of the ps command can be overwhelming and difficult to parse for specific process information. Extracting key details like CPU usage, memory, and command name efficiently is often a manual chore.

The Solution: Combine ps with awk for precise control over process output.

ps aux | awk '{printf "%-10s %-30s %-5s %-5s %-10s %s\n", $1, $11, $3, $4, $6, $12}'

Why it works: ps aux provides a comprehensive snapshot of running processes. awk then acts as a powerful text processor, allowing us to select, reorder, and format specific columns (fields) from the ps output. The printf command within awk ensures neat, aligned columns.

Pro-Tip: To focus on processes using a specific amount of CPU (e.g., > 5%), you can add a condition to awk: ps aux | awk '$3 > 5.0 {printf "%-10s %-30s %-5s %-5s %-10s %s\n", $1, $11, $3, $4, $6, $12}'

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

0 0 votes
Article Rating
Exit mobile version