Site icon New Generation Enterprise Linux

Tame Your `ps` Output: Focused Process Info with `awk`

Quick Tip

Tame Your `ps` Output: Focused Process Info with `awk`

Challenge: The output of the `ps` command can be overwhelming, especially on busy systems. You often need to quickly identify specific processes based on their CPU usage, memory consumption, or command arguments, but sifting through endless columns is time-consuming.

The Solution: Combine `ps` with `awk` to filter and reformat the process information for enhanced readability and targeted analysis.

ps aux | awk 'NR==1 || /your_process_name/ {print $0}' # Or for specific columns like PID, %CPU, %MEM, COMMAND: ps aux | awk 'NR==1 || /your_process_name/ {printf "%-8s %-8s %-8s %s\n", $1, $3, $4, $11}'

Why it works: `awk` is a powerful text-processing tool that excels at pattern matching and field manipulation. By piping the output of `ps aux` (which provides a comprehensive snapshot of processes) to `awk`, you can easily select specific lines (e.g., lines containing ‘your_process_name’) or format output to display only the most critical columns. The `NR==1` condition ensures the header row is always included.

Pro-Tip: To sort the output by CPU usage, pipe the `ps aux` output to `sort -k3nr` before piping to `awk`. For example: ps aux | sort -k3nr | awk 'NR==1 || /your_process_name/ {printf "%-8s %-8s %-8s %s\n", $1, $3, $4, $11}'

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

0 0 votes
Article Rating
Exit mobile version