Site icon New Generation Enterprise Linux

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

Quick Tip

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

Challenge: The default output of the `ps` command can be verbose and difficult to parse for specific process information, especially when you need to quickly identify key metrics like CPU usage, memory consumption, or the full command line of running processes.

The Solution: Leverage `awk` with `ps` to tailor your output for clarity and efficiency.

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

Why it works: This command uses `ps aux` to get detailed process information and then pipes it to `awk`. `awk`’s `printf` function allows us to precisely format the output, selecting and aligning specific columns (user, PID, CPU%, MEM%, VSZ, COMMAND) for easier readability.

Pro-Tip: For an even more concise output focusing only on PID and Command, try: ps -eo pid,comm.

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

0 0 votes
Article Rating
Exit mobile version