Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

How do I save the output of a command to a file?

Is there a way without using any software? I would like to know how.

share|improve this question

4 Answers 4

up vote 28 down vote accepted

Yes it is possible, just redirect the output to a file:

someCommand > someFile.txt  

Or if you want to append data:

someCommand >> someFile.txt

If you want stderr too use this:

someCommand &> someFile.txt  

or this:

someCommand &>> someFile.txt  
share|improve this answer

You can also use tee to send the output to a file:

command | tee ~/outputfile.txt

A slight modification will catch stderr as well:

command 2>&1 | tee ~/outputfile.txt

or just the same with less characters to type:

command |& tee ~/outputfile.txt

tee is useful if you want to be able to capture command output while also viewing it live.

share|improve this answer

An enhancement to consider -

Various scripts will inject color codes into the output which you may not want cluttering up your log file.

To fix this, you can use the program sed to strip out those codes. Example:

command 2>&1 | sed -r 's/'$(echo -e "\033")'\[[0-9]{1,2}(;([0-9]{1,2})?)?[mK]//g' | tee ~/outputfile.txt
share|improve this answer

You can pipe the command output to a file:

your_command >/path/to/file

Or append the command output to a file

your_command >>/path/to/file
share|improve this answer
    
Thanks a lot ! is there any Limits ? like the max size of the file ? –  led-Zepp Feb 14 '14 at 19:55
2  
The max file size is just limited through the file system –  chaos Feb 14 '14 at 19:59
    
This answer will not save stderr. Use &> , see stackoverflow.com/questions/637827/… and tldp.org/LDP/abs/html/io-redirection.html –  bodhi.zazen Feb 14 '14 at 20:16
2  
The OP never asked to save stderr –  chaos Feb 14 '14 at 20:18
1  
xD, if that's the thing: script is also a software. You can use a pencil if you don't want to use software =) –  chaos Feb 14 '14 at 21:14

protected by Community Mar 12 at 6:57

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

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