Azaksai
Azaksai

Reputation: 377

Top command to show the %cpu in descending order

I would like to have the cpu percentage in decending order. When I give the command :

top -bn 1 | grep "^ " | awk '{ printf("%-8s  %-8s \n", $2, $9); }' | head -8

It shows processes which are not the top most using CPU.

Upvotes: 8

Views: 40606

Answers (4)

Codizon
Codizon

Reputation: 447

You can use the following :

top -o +%CPU

Upvotes: 1

S. Friese
S. Friese

Reputation: 11

Try top with the -u flag: top -u

Upvotes: 1

Othi
Othi

Reputation: 356

In your command, you have

grep "^ "

which filters out lines that do not start with a space.

With this, you're filtering out processes that have PIDs longer than 4 characters, since the top command left pads the PIDs to 5 characters.

Use grep "^[0-9 ]" instead.

Upvotes: 1

Andrew Cassidy
Andrew Cassidy

Reputation: 2998

Run top as a process (I'm using Ubuntu 14.04)

top

Once in top...

P <- Sort by CPU usage

M <- Sort by MEM usage

z <- Add cool visual colors

x <- Highlight column you are currently sorting by

Upvotes: 37

Related Questions