Site icon New Generation Enterprise Linux

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

Quick Tip

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

Challenge: The default output of the `ps` command can be overwhelmingly verbose, making it difficult to quickly find specific process information like a process ID (PID) associated with a particular command name or user.

The Solution: Leverage `awk` to filter and format the `ps` output to display only the essential columns you need, significantly improving readability and searchability.

ps aux | awk '$11 ~ /my_process_name/ { print $1, $2, $11 }'

Why it works: This command pipes the full output of `ps aux` to `awk`. `awk` then iterates through each line, and the condition `’$11 ~ /my_process_name/’` checks if the 11th field (which typically contains the command name) matches “my_process_name”. If it matches, it prints the username (field 1), PID (field 2), and command name (field 11).

Pro-Tip: To display only the PID of a process, you can simplify it further: ps aux | awk '/my_process_name/ {print $2}'

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

0 0 votes
Article Rating
Exit mobile version