Skip to main content

How to redirect stdout to a file, and stdout+stderr to another one? [Resolved]

How can I achieve

cmd >> file1 2>&1 1>>file2

That is, the stdout and stderr should redirect to one file(file1) and only stdout(file2) should redirect to another(both in append mode)?


Question Credit: Swarna Gowri
Question Reference
Asked May 13, 2019
Posted Under: Unix Linux
3 views
2 Answers

Problem is that when you redirect your output, it's not available anymore for the next redirect. You can pipe to tee in a subshell to keep the output for the second redirection:

( cmd | tee -a file2 ) >> file1 2>&1

or if you like to see the output in terminal:

( cmd | tee -a file2 ) 2>&1 | tee -a file1

credit: RoVo
Answered May 13, 2019
Your Answer
D:\Adnan\Candoerz\CandoProject\vQA