Site icon New Generation Enterprise Linux

Taming `ps` Output with Custom `awk` Formatting

Quick Tip

Taming `ps` Output with Custom `awk` Formatting

Challenge: The output of the `ps` command can be overwhelming, especially when dealing with a large number of processes. Extracting specific, useful information like PID, CPU usage, and command name can be tedious with standard `grep` or `cut`.

The Solution: Leverage `awk` to elegantly parse and reformat the `ps` output for a cleaner, more focused view.

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

Why it works: `awk` processes the output line by line, and we instruct it to print only the Process ID (PID) in the second column (`$2`), CPU usage in the third (`$3`), memory usage in the fourth (`$4`), and the command name (starting from the eleventh column, `$11`) using `printf` for formatted output. This creates a concise and readable summary.

Pro-Tip: To see only processes owned by a specific user (e.g., ‘root’), pipe the output through `grep ‘root’` *before* piping to `awk`: ps aux | grep 'root' | awk '{printf "%-10s %-5s %-5s %-s\n", $2, $3, $4, $11}'

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

0 0 votes
Article Rating
Exit mobile version