Site icon New Generation Enterprise Linux

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

Quick Tip

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

Challenge: The default output of the `ps` command can be overwhelming, displaying a vast amount of information about running processes. Often, you only need specific details like PID, command, and CPU/memory usage.

The Solution: Combine `ps` with `awk` to filter and format the output for precisely the information you need.

ps aux | awk '{print $2, $11, $3, $4}'

Why it works: `ps aux` lists all processes with detailed information. `awk` then processes this output line by line, printing the specified columns (PID, Command, %CPU, %MEM in this case). You can adjust the column numbers to display different `ps` fields.

Pro-Tip: To sort processes by CPU usage in descending order, pipe the output to `sort -rnk3` (e.g., `ps aux | awk ‘{print $2, $11, $3, $4}’ | sort -rnk3`).

Linux Tips & Tricks | © ngelinux.com | 7/1/2026

0 0 votes
Article Rating
Exit mobile version