Quick Tip
Taming Process Sprawl: Focused `ps` Output with `awk`
Challenge: The output of the `ps` command can be overwhelming, especially on busy systems. It’s often difficult to quickly find specific processes or understand their resource usage without manual filtering or complex `grep` commands.
The Solution: Leverage the power of `awk` to filter and format the `ps` output for targeted information.
ps aux | awk '/[u]sername/ {print $0} /[p]rocess_name/ {print $0}'
Why it works: This command combines `ps aux` to get detailed process information with `awk`. `awk` then filters the output, printing lines that match either the specified username (case-insensitive due to the `[u]sername` pattern) or the process name. This allows for precise, pattern-based extraction of relevant process data.
Pro-Tip: For even more specific filtering, you can use `awk`’s conditional logic and field manipulation. For example, `ps aux | awk ‘{ if ($1 == “root” && $11 ~ /nginx/) print $0 }’` will show all nginx processes run by root.
Linux Tips & Tricks | © ngelinux.com | 6/10/2026
