Basic Linux Tutorial
Computer Tutorial

Standard Error Redirection



Error Redirection

The stderr stream can be redirected in a similar fashion as stdin or stdout. There is no special symbol for redirecting stderr. The same ">" symbol is used but with the number 2 attached in front of it. We use "2>" for stderr redirection to tell the shell that we want to redirect the error messages instead of stdout (for which the file descriptor value is 0).

Error Redirection

We tried to list a file with name xyz and the command result shows that this file does not exist.
$ ll xyz >abc
xyz not found.
We tried to redirect the output, but still the message is displayed on our screen.
$ ll xyz 2>abc
$
Now there is nothing displayed because the error message has been stored in a file with name abc.