Javatpoint Logo
Javatpoint Logo

Linux Error Redirection

2> stderr

Command '2>' redirects the error of an output.It helps us you to keep our display less messy by redirecting error messages.

Example:

Linux Error Redirection1

Look at the above snapshot, by using command "zcho hyii 2> /dev/null" (here echo command is wrong), we didn't get any error message. But when we use command "zcho hyii" error message is displayed in the terminal. Hence, '2>' redirects the error message in the mentioned directory keeping your terminal error message free.


2>&1

This command helps in redirecting the stdout and stderr in the same file.

Example:

Linux Error Redirection2

Look at the above snapshot, 'abc.txt and error.txt' is directing to the same file 'newfile.txt'.

Note: Order of redirections is really important.

If you'll write:

then, stdout and stderr both will be directed to the file dirlist.

But if you'll write:

then, only stdout will be redirected to dirlist. This is because, before the stdout is redirected to dirlist, stderr has made a copy of stdout.

Next TopicBasic Unix Tools





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA