Taming `ps` Output: Focused Process Info with `awk`
Quick Tip
Taming `ps` Output: Focused Process Info with `awk`
Challenge: The output of the ps command can be incredibly verbose, making it difficult to quickly identify specific processes or extract precise information about them.
The Solution: Leverage the power of awk to filter and format the output of ps for highly targeted process information.
ps aux | awk '$1 == "root" && $11 ~ /sshd/ { print $2, $11 }'
Why it works: This command pipes the full output of ps aux to awk. awk then processes each line, filtering for lines where the first column (user) is “root” and the eleventh column (command) contains “sshd”. It then prints only the PID (second column) and the command name (eleventh column).
Pro-Tip: Use ps -eo pid,user,cmd | grep sshd for a more direct filtering approach if you don’t need complex conditional logic.
Linux Tips & Tricks | © ngelinux.com | 6/13/2026
