Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 12 down vote accepted

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.

share|improve this answer

Goto 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.

Learn Bash Scripting:

share|improve this answer
As I said I did it but it store some binary character within it. – Behzadsh Nov 10 '10 at 8:16
thanks for tutorial – Behzadsh Nov 10 '10 at 8:54

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.