How do I capture the output of “top” to a file?

top -b -n1 > /tmp/top.txt
This will run top once write the output to a file and exit. The command top can also be run so that it will give multiple reports. To run top 5 times and wait 5 seconds between each output the command would be:
top -b -n5 -d5 > /tmp/top.txt

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.