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?
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.)
ls, and execute it with no interference from the late output.>(tee err.log >&2) so that the error messages go back to standard error, rather than standard output. It only makes a difference if the line occurs inside another script which might be redirecting its standard error elsewhere, though.cmd 2>&1 | tee /tmp/error.log