/Dev/null2> & amp; 1 details

Source: Internet
Author: User
/Dev/null2 & gt; & amp; 1 today, a friend suddenly saw the following content in his own Linux maintained:/var/spool/cron/root: www.2cto. com3019 ***/usr/bin/** dcon. sh & gt;/dev/null2 & gt; & amp; 15923 ** 1-7/home /...
/Dev/null 2> & 1 details today a friend suddenly saw the following content in his own Linux maintained:/var/spool/cron/root: www.2cto.com 30 19 ****/usr/bin/** dcon. sh>/dev/null 2> & 159 23 ** 1-7/home/s **-log/squid-log.renew>/dev/null 2> & 150 1 ** 1- 7/usr/local/src/** log. sh>/dev/null 2> & 120 2 ** 1-7/home/sq **-log/** log>/dev/null 2> & 130 2 ** 1-7/home/sq **-log/** log.0130 22 ****/bin/** sync>/dev/null 2> & 100 8 ** 1-7 /home/**-log/rmco Re>/dev/null 2> & 100 16 ** 1-7/home/**-log/rmcore>/dev/null 2> & 1 he asked me why to use/ dev/null 2> & 1. this command redirects all standard output and error output to/dev/null, that is, it discards all generated information. next, let's take a look at the differences between command> file 2> file 2> & 1. www.2cto.com first ~ Command> file 2> file refers to sending the standard output information and error output information generated by the command to file. command> file 2> file: both stdout and stderr are directly sent to file. the file will be opened twice, so that stdout and stderr will overwrite each other, in this way, both FD1 and FD2 are used to seize the file pipeline at the same time. command> file 2> & 1 directly sends stdout to file. after stderr inherits the FD1 pipeline, it is sent to file. at this time, the file is opened only once, only one pipeline FD1 is used, which includes stdout and stderr content. 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 most cases, we use command> file 2> & 1.
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.