Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

way to sort by CPU% on 'top' by default? [closed]

Tags:

macos

freebsd

When i run top on my Macbook (BSD?) i almost always want to sort by CPU%

it dosent seem to be the default, so I wind up typing 'o' (to sort) and type in 'cpu' and hit enter all the time!

is there a way to make sort-by-CPU% the default or something?

like image 921
David Lam Avatar asked Jan 08 '15 23:01

David Lam


4 Answers

%CPU is the default sort column on every system I've ever used. But if it's not, you can press Shift-P to sort by %CPU. Note that it's not listed in interactive help, only the man page.

M         %MEM
N         PID
P         %CPU
T         TIME+
like image 145
John Kugelman Avatar answered Oct 29 '22 09:10

John Kugelman


top -o +%CPU

As John Kugelman said, usually %CPU is a default sort column. Anyway, reading man top(1) seems a good idea.

like image 5
praetorian droid Avatar answered Oct 29 '22 10:10

praetorian droid


Looking at the top manpage, you can use option -o %CPU, although that should already be the default. You could create an alias in your .bashrc (alias top='top -o %CPU') to make this permanent.

-o  :Override-sort-field as:  -o fieldname
            Specifies  the  name of the field on which tasks will be sorted, independent of what is reflected in the configuration file.  You can prepend a '+' or '-' to the field name to
            also override the sort direction.  A leading '+' will force sorting high to low, whereas a '-' will ensure a low to high ordering.

            This option exists primarily to support automated/scripted batch mode operation.
like image 3
tux3 Avatar answered Oct 29 '22 09:10

tux3


Another way is to establish the sorting you prefer in top and then press W to save the configuration. Next time you start top it is going to load the config.

Press h in top to see keyboard shortcuts.

like image 2
Maxim Egorushkin Avatar answered Oct 29 '22 09:10

Maxim Egorushkin