Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sorting by integer value

I am writing a bash script and I am using

ps -e -o %cpu

command.

I would like to have output of sorted %cpu values (descending). How to do that? I know that I should use sort command but I don't know how.

like image 511
user1926550 Avatar asked Dec 08 '22 16:12

user1926550


1 Answers

 ps -e -o %cpu | sort -nr

n for numeric, r for reverse. If you also want to remove the header:

 ps -e -o %cpu | sed '1d' | sort -nr
like image 140
perreal Avatar answered Dec 11 '22 10:12

perreal