1

I would like to put up a batch script that include a step where I want to output the results of command "top" in Linux to a text file. There is one catch here though, I would like to rank the top results by memory usage. I know it is easy when you have the command windows (Shift+F and n will do the trick) but I have not found any possible solution to do so in a bash script.

Could you help? Many thanks in advance.

animuson
  • 53,861
  • 28
  • 137
  • 147
AZhu
  • 1,312
  • 6
  • 22
  • 40

1 Answers1

4

You could create a ~/.toprc with W in top after Shift+F and n. Then sorting by memory usage is default. After that, you only need top -b -n1 >top.txt.

glglgl
  • 89,107
  • 13
  • 149
  • 217