Redirect all output to file

Rayne picture Rayne · Jul 13, 2011 · Viewed 1.1M times · Source

I know that in Linux, to redirect output from the screen to a file, I can either use the > or tee. However, I'm not sure why part of the output is still output to the screen and not written to the file.

Is there a way to redirect all output to file?

Answer

Op De Cirkel picture Op De Cirkel · Jul 13, 2011

That part is written to stderr, use 2> to redirect it. For example:

foo > stdout.txt 2> stderr.txt

or if you want in same file:

foo > allout.txt 2>&1

Note: this works in (ba)sh, check your shell for proper syntax