Capture top command output in a file

Capture top command output in a file

The output of top command can be captured as follows
top -b -n1 > /tmp/top1.txt
This will run top command once and write the output to a file, then exit.
To run top 3 times with an interval of 5 seconds, run the following command
top -b -n3 -d5 > /tmp/top.txt
Written by actsupp-r0cks