5

I want to sort the memory usage in top command as default. So that i do not have to sort in every i run top command.

How to do that?

Thanks in advance....

Zozzizzez
  • 497

1 Answers1

15

Start it with

top -o %MEM

You can create an alias: alias top='top -o %MEM' in ~/.bashrc) for this.

Easier method: top can save to a configuration using W.

W :Write-the-Configuration-File This will save all of your options and toggles plus the current display mode and delay time. By issuing this command just before quitting top, you will be able to restart later in exactly that same state.

It saves to ~/.toprc. Going back to default is the same as removing ~/.toprc.

Rinzwind
  • 310,127
  • Couldn't you specify the sort order in the config file? – Jos Aug 21 '20 at 10:20
  • Yep. Enter your command, press W to write the config file, next time top sorts by %MEM again. – Jos Aug 21 '20 at 10:22
  • Minor point: on my system, no backup file is created. – Jos Aug 21 '20 at 10:29
  • To be precise, no backup file is created on my 18.04 server or 20.04 laptop. On the laptop, the config file is written to $HOME/.config/procops. – Jos Aug 21 '20 at 10:49
  • Hmmm Ill remove it :( My server did but ... it is ehm older than we accept here :D – Rinzwind Aug 21 '20 at 10:51