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 overwhelming, especially when you’re looking for specific information about a process, like its PID, CPU usage, or memory consumption. Parsing this verbose output manually is time-consuming and error-prone.

The Solution: Use `awk` to filter and format the output of `ps` to display only the columns you need.

ps aux | awk '/[p]rocess_name/ {print $2, $3, $4, $11}'

Why it works: `ps aux` provides a comprehensive snapshot of running processes. `awk` then processes this output line by line. The pattern `/[p]rocess_name/` efficiently filters for lines containing “process_name” (the brackets prevent `awk` itself from matching the pattern). For matching lines, `{print $2, $3, $4, $11}` prints specific fields (PID, %CPU, %MEM, and Command) separated by spaces.

Pro-Tip: You can customize the fields to display by changing the numbers after the ‘$’ sign. For example, `$1` is USER, `$11` is COMMAND.

Linux Tips & Tricks | © ngelinux.com | 6/15/2026

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Newest
Oldest Most Voted