>/dev/null 2>&1 The meaning of this sentence

Source: Internet
Author: User

1 indicates standard output, 2 indicates standard error output

2>&1 indicates that 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 (that is, output together).

In general, standard output and standard error output are screens, so why use it? The reason is the redirection of standard output, 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 >/dev/null 2>&1

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.

This is essentially discarding your standard output and error output, which you can do when you don't want a command or program to produce any output.

>/dev/null 2>&1 The meaning of this sentence

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.