Skip to content

Instantly share code, notes, and snippets.

@Stephanvs
Created December 9, 2020 12:44
Show Gist options
  • Save Stephanvs/03583990622836fb25a10c45ccf892d3 to your computer and use it in GitHub Desktop.
Save Stephanvs/03583990622836fb25a10c45ccf892d3 to your computer and use it in GitHub Desktop.
Saving terminal output to a file

Tags

  • unix
  • terminal
  • stdout
  • stdin
  • redirect

Question

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

Answer

Yes it is possible, just redirect the output (AKA stdout) to a file:

SomeCommand > output.txt

Or if you want to append data:

SomeCommand >> output.txt

If you want stderr as well use this:

SomeCommand &> output.txt  

or this to append:

SomeCommand &>> output.txt

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

SomeCommand 2>&1 | tee output.txt

(If you want the output only, drop the 2 above)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment