What does >/dev/null 2>&1 mean [turn]

Source: Internet
Author: User

In some shell scripts, especially in crontab scripts, >/dev/null2>&1 is often seen as such.

In fact, this is very good understanding. We explain in two parts. 1. >/dev/null

Everyone knows that ">" (Right angle bracket) in the Unix/linux shell means input to the meaning of the ">" to the left of the content to the ">" right.
For example, Echo text>1.txt the text into the 1.txt file.
So what is "/dev/null"? It represents an empty device, that is, a device that does not exist . In other words, discard the content on the left side of ">" Without outputting.     2. 2>&1

This is actually composed of three parts: 2, >&, 1. Let's start by figuring out what 2 and 1 here mean. In/usr/include/unistd.h, you can find the following code.

#define STDIN_FILENO 0
#define Stdout_fileno 1
#define Stderr_fileno 2

This is three different streams.
2 represents stderr.
1 represents Sdtout.
&> indicates that the left side of the symbol is exported as the right side of the symbol.
2&>1 is to put the stderr as stdout output.

Now we combine these two parts to see. 2&>1 defines stderr as the standard stdout stream output, and then the stdout content is written to/dev/null, which means it is discarded.
The conclusion is that no matter what command is executed, even if there is an error in the run there will be no echo.



Linux Device management is closely associated with the file system, associating devices with files so that system calls can operate the device directly in the same way as the operation file. A variety of devices are stored in the form of files in the/dev directory, known as device files. The application can open, close, and read and write these device files to complete the operation of the device, just as you would a normal data file. In order to manage these devices, the system is numbered for the device, and each device number is divided into the main device number and the secondary device number. The main device number is used to differentiate between different kinds of devices, while the secondary device number is used to differentiate multiple devices of the same type. For common devices, Linux has a conventional number, such as the main device number of the hard disk is 3.

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.