Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

How do I save terminal output to a file?

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

2 Answers

akshay1995
just redirect the output (AKA stdout) to a file:

SomeCommand > SomeFile.txt

Or if you want to append data:

SomeCommand >> SomeFile.txt

If you want stderr as well use this:

SomeCommand &> SomeFile.txt

or this to append:

SomeCommand &>> SomeFile.txt

if you want to have both stderr and output displayed on the console and in a file use this:

SomeCommand 2>&1 | tee SomeFile.txt

(If you want the output only, drop the 2 above)
RoliMishra
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 slightly shorter and less complicated:

command |& tee ~/outputfile.txt

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

Login / Signup to Answer the Question.