Sunday, 10 July 2016

linux - Redirect all output to file





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



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



No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...