Crontab Common/dev/null 2>&1 detailed

Source: Internet
Author: User

Most of the crontab planning tasks will be years to the end of the >/dev/null 2>&1, what is the meaning of it.

> is redirected
/dev/null represents empty device files
1 indicates stdout standard output, the system default is 1, so ">/dev/null" is equivalent to "1>/dev/null"
2 indicates stderr standard error
& means equal to, 2>&1, indicating 2 output redirection equals 1


The whole sentence means that the standard output redirects to the empty device file, that is, not outputting any information to the terminal, the standard error output redirection is equivalent to the standard output, because the standard output is redirected to the empty device file, so the standard error output is redirected to the empty device file


What is the difference between command > file 2>file and command > file 2>&1 ?

Command > File 2>file means that the standard output information generated by the command, and the wrong output information, are sent to file. command > file 2>file such a notation, StdOut and stderr are sent directly to file, file will be opened two times, so that stdout and stderr will cover each other, which writes quite a lot of FD1 and FD2 two of the pipelines to preempt file.
and command >file 2>&1 This order will stdout directly to file, StdErr inherited the FD1 pipeline, and then sent to file, at this time, file was only opened once, also only used a pipeline FD1, It includes the contents of stdout and stderr.
In terms of IO efficiency, the previous command is less efficient than the one in the latter, so when writing a shell script, more often than not, we use command > file 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.