Reputation: 68738
Under Linux/bash I want to run a command and send standard output to foo.txt as well as combined standard output and standard error to bar.txt:
$ cmd < input.txt 1>foo.txt 1+2>bar.txt ???
What's the easiest way to do this?
To send just stdout is:
$ cmd > foo.txt
To send both stdout/stderr is:
$ cmd &> bar.txt
However trying to combine:
$ cmd > foo.txt &>bar.txt
Causes foo.txt to be empty.
Upvotes: 1
Views: 477
Reputation: 500903
The following should do it:
(cmd | tee out.txt) &> both.txt
That'll redirect stdout
to out.txt
and both stdout
and stderr
to both.txt
.
Upvotes: 1
Reputation: 71009
You can not have two redirections of the output stream at the same time. Easiest way to do what you want is to pipe output to the tee command.
Upvotes: 1