Supercharge Your `ps` Output with Custom `awk` Formatting

Quick Tip

Supercharge Your `ps` Output with Custom `awk` Formatting

Challenge: The standard `ps` command can produce a lot of information, making it difficult to quickly find specific process details. Sometimes you just need to see the process ID (PID), user, and CPU/memory usage in a clean, custom format.

The Solution: Leverage the power of `awk` to filter and format the output of `ps` to display exactly what you need.

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

Why it works: This command pipes the full process list (`ps aux`) to `awk`. `awk` then uses `printf` to format specific columns: `$2` (PID), `$1` (User), `$3` (CPU %), and `$11` (Command Name), ensuring a clean, aligned output. The `%-Ns` format specifier in `printf` left-aligns strings within a field of width N.

Pro-Tip: To include the virtual memory size (`%MEM`), replace `$3` with `$4` and adjust the `printf` format string accordingly, e.g., ps aux | awk '{printf "%-10s %-15s %-5s %-5s %s\n", $2, $1, $3, $4, $11}'.

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

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Newest
Oldest Most Voted