Site icon New Generation Enterprise Linux

Taming `ps` Output: Focused Process Info with `awk`

Quick Tip

Taming `ps` Output: Focused Process Info with `awk`

Challenge: When dealing with a large number of running processes, the output of the `ps` command can be overwhelming. Extracting specific process details like PID, CPU usage, and memory can be tedious.

The Solution: Leverage `awk` to filter and format `ps` output for precision.

ps aux | awk '{print $1, $2, $4, $11}'

Why it works: The `ps aux` command lists all running processes with detailed information. `awk` then processes this output line by line, printing only the fields specified by their column numbers (e.g., $1 for USER, $2 for PID, $4 for %CPU, $11 for COMMAND). You can adjust the column numbers to extract precisely the data you need.

Pro-Tip: For even more targeted filtering, combine `awk` with `grep`. For example, `ps aux | grep ‘nginx’ | awk ‘{print $2, $4}’` will show only the PID and CPU usage for processes related to ‘nginx’.

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

0 0 votes
Article Rating
Exit mobile version