>/dev/null 2>&1 The meaning of this sentence and the meaning of its use

Source: Internet
Author: User

This may be used in the shell, including DOS.

Null is something called a null bucket, and the benefit of redirecting the output to it is that the file size is not constantly increasing due to too much content in the output. In fact, you think that null is nothing, that is, the output of the command is discarded.

1 indicates standard output, 2 indicates standard error output, 2>&1 indicates the standard error output is redirected to standard output, so that the normal output and error output of the program or command can be output in standard output.

In general, standard output and standard error output are screens, so why use it? The reason is the redirection of the standard output. Your example is redirected to null if you redirect to a file, for example:
Dir > OUT.txt
Indicates that standard output is redirected to the OUT.txt file. If the dir command fails, the error message is not output to the OUT.txt file, and the error message is still output to the screen-standard error output. To redirect the correct information and the wrong information to the OUT.txt file, you need to redirect the standard error output of the error message to standard output. The command is as follows:
dir > OUT.txt 2>&1
Redirecting to NULL is a reason.
dir > Null 2>&1

>/dev/null 2>&1 The meaning of this sentence and the meaning of its use

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.