Linux>/dev/null

Source: Internet
Author: User

Unix has several input and output streams, which correspond to numbers as follows:

0-standard input stream (stdin)

1-standard output stream (stdout)

2-standard error stream (stderr)

Command results can be defined in the form of>.
1./dev/null indicates that the device file is empty.
2. Redirection symbols:> redirect output to overwrite the file;

> Redirected output without overwriting the file;

1 indicates stdout standard output. The default value is 1. Therefore, ">/dev/null" is equivalent to "1>/dev/null". If no number is added, the default Redirection action is for stdout (1). For example, "ls-L> result" is equivalent to "ls-L 1> result ".
& Indicates the meaning of "equivalent", 2> & 1, indicating that 2's output redirection is equivalent to 1;

1>/dev/null indicates that the standard output is redirected to an empty device file, that is, no information is output to the terminal. In other words, no information is displayed.
2> & 1 the standard error output redirection is equivalent to the standard output. Because the standard output has been redirected to the empty device file, the standard error output is also redirected to the empty device file, that is: is to redirect stderr to stdout and display it together on the screen.

CMD>/dev/null 2>/dev/null and CMD>/dev/null 2> & 1:

1. CMD>/dev/null 2>/dev/null: Send the standard output information and error output information generated by the command to/dev/null, stdout and stderr are both directly sent to/dev/null, And/dev/null will be opened twice, so that stdout and stderr will overwrite each other, in this way, both fd1 and fd2 are used to seize/dev/null pipelines at the same time.

2. CMD>/dev/null 2> & 1: Send stdout directly to/dev/null. After stderr inherits the fd1 pipeline, it is sent to/dev/null, /dev/null is opened only once, and only one pipeline fd1 is used, which includes stdout and stderr content. 3. in terms of Io efficiency, the efficiency of the previous command is lower than that of the subsequent command. Therefore, when writing shell scripts, in many cases, we use cmd>/dev/null 2> & 1.

 

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.