Score:0

how to run the top command with 'm' already pushed?

us flag

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.

hr flag
If you want those as the *defaults*, consider using a .toprc file - see for example [How to set memory usage sort in top command as default?](https://askubuntu.com/questions/1268933/how-to-set-memory-usage-sort-in-top-command-as-default)
vanadium avatar
cn flag
'man top' may contain the answer. Could be the -o option.
cn flag
@vanadium it is ;-)
Score:1
cn flag

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.

us flag
this solution solves b) but not a)
us flag
i want the output to show the memory percent graph AND ALSO sort by mem decreasing
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.