Master `ps` Output with Custom `awk` Formatting
Quick Tip
Master `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.
The Solution: Leverage `awk` to filter and format the `ps` output for precise process details.
ps aux | awk '$1 == "root" { print $2, $11 }'
Why it works: This command uses `ps aux` to list all running processes and pipes the output to `awk`. `awk ‘$1 == “root” { print $2, $11 }’` then filters for lines where the first field (`$1`) is “root” and prints the second field (PID) and the eleventh field (command name).
Pro-Tip: Use `ps -ef` and adjust the field numbers in `awk` to match the desired columns for different `ps` output formats. For example, `ps -ef | awk ‘$3 ~ /bash/ { print $2, $8 }’` to find PIDs and commands of processes containing “bash” in their effective user ID.
Linux Tips & Tricks | © ngelinux.com | 5/10/2026
