notice that if you would like to keep "top" command for a script, you could use -b option ("-b" option means "batch mode operation"), this option allows you to redirect the output into a file.
Examples:
top one shoot batch mode : top -bn 1 2>&1 1> /tmp/topN
top sorted by memory usage one shoot batch mode : top -ban 1 2>&1 1> /tmp/topAN
The
-n
switch is what you search:See the manpage
If you want to stop
top
command just press q.Notice: If you tend to use
top
in a script, I need to saytop
is not meant for scripts, useps
instead.notice that if you would like to keep "top" command for a script, you could use
-b
option ("-b" option means "batch mode operation"), this option allows you to redirect the output into a file.Examples:
top -bn 1 2>&1 1> /tmp/topN
top -ban 1 2>&1 1> /tmp/topAN