0

I want to run top so that it opens as if you hit the m key, what I really want is this:

How to run ''top'' command 1 time and exit?

But I want to

a) have the 'm' key hit b) sort by memory (shift-m)

Can this be done from the command line?

Thanks, Kevin

update - showing what i am seeking from command line without having to hit any key:

enter image description here

Just an update to clarify i need BOTH the sort by AND the memory showing, in a single command line, the given solution only solves the sort request. Thanks for any help.

1 Answers1

1

from command line you can sort with -o. On MEM this would be

top -o +%MEM

if from high to low.

See man top:

-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.

Rinzwind
  • 299,756