Command-Line – How to Echo Output of Top into a Text File

command lineoutputtop

I want to write batch or something, that will write output of top into a file on login.

I did top >> output-file, but it contains some strange character!

Can somebody give a simple tutorial about how to write batch file in Linux?

Best Answer

Try the following

top -b -n1 > filename.txt

The -b is for batch mode, which should prevent the strange characters. The -n1 tells it to only print one iteration.