The difference between >/dev/null 2>&1 and 2>&1 >/dev/null and &>/dev/null in the shell

Source: Internet
Author: User

By default, there are always three files open, standard input (keyboard input), standard output (output to screen), standard error (also output to screen), and their respective file descriptors are 0,1,2. So let's take a look at the differences between the following redirection methods:

>/dev/null 2>&1

In fact, it should be equivalent to this: 1>/dev/null 2>/dev/null, by default is 1, standard output, so generally omitted. The & symbol, followed by the required file descriptor. cannot be written as 2>1, so it becomes a standard error redirect to a file named 1, instead of redirecting standard errors to standard output. So here it is: The standard output is redirected to the/dev/null, and the standard error is redirected to the standard output, so the standard output and standard error are redirected to the/dev/null

2>&1 >/dev/null

At first glance, what's the difference between this and that one? Standard error redirected to standard output, and standard output redirected to/dev/null? Shouldn't we all redirect/dev/null at the end? That's how I understand it! An instruction either produces a standard error at the same time or produces a standard output. When the output standard is wrong, the standard error is redirected to the standard output, and the standard output is output to the screen. At this point the standard output was not redirected to/dev/null, so it was printed on the screen. When the standard output is produced, then it is not a standard error, 2>&1 is not valid, so the standard output redirects dev/null, does not print to the screen. So the end result will be: standard error printing to the screen, and standard output not printing to the screen.

From:http://blog.csdn.net/reyleon/article/details/11595985

The difference between >/dev/null 2>&1 and 2>&1 >/dev/null and &>/dev/null in the shell

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.