Operating System - HP-UX
1822512 Members
2513 Online
109642 Solutions
New Discussion юеВ

How to sort the output of the top command

 
Jan vd Vlugt
Occasional Advisor

How to sort the output of the top command

When running the top command i will show all the running processes at the top of the list. Is there a way to sort on state and cpu?
2 REPLIES 2
Jonathan Fife
Honored Contributor

Re: How to sort the output of the top command

Probably the best you're going to do using the top command is redirecting it to a file and then sorting that. You'll get the headers and footers in the file too, though.

Why not use ps instead?

ps -elf | sort -nr +5 #sort by cpu
ps -elf | sort -r +1 #sort by state
Decay is inherent in all compounded things. Strive on with diligence
spex
Honored Contributor

Re: How to sort the output of the top command

Hi Jan,

'top' will not do this interactively. Use 'ps':

# UNIX95= ps -e -o pcpu= -o state= -o pid= -o args= | sort -r -k2,1 | head -20

PCS