How to echo output of a top into a text file?

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.


Go to terminal and type:

user@ubuntu:~$ top > filename.txt

The output of top command will be now stored in a text file which is located in your Home directory.

See: Bash scripting Tutorial.