Output of top into text file, but ranked by memory
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.
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
.
精彩评论