Reputation: 6831
If I use this
cmd 2>/var/error.log
Then my error goes to that file but then I can't see on screen.
Is there any way I can simultaneously show it on screen as well as send to file?
Upvotes: 2
Views: 490
Reputation: 113834
This will display both stdout and stderr on the terminal while only sending stderr to err.log
:
cmd 2> >(tee err.log >&2)
>(...)
is process substitution. (The space between the two consecutive >
is essential.) This sends stderr and only stderr to the tee
command.
The >&2
causes the error messages remain in stderr. This would be important, for example, if this line occurs inside some script whose stdin or stderr is being redirected. (Hat tip: Chepner.)
Upvotes: 3