Crontab Common/dev/null 2>&1 detailed

Source: Internet
Author: User


most crontab scheduled Tasks, at the end of the command line will take >/dev/null 2>&1, what is the role of it?

    • The following is an explanation:

> delegate redirection;

/dev/null represents an empty device file, equivalent to a recycle Bin. null is a thing called a null keg that redirects the output to its good

is: The file size is not increased because of too much output, which means that the output of the command is discarded.

1 represents the stdout standard output, the system default value is 1, so ">/dev/null" is equivalent to "1>/dev/null"

2 indicates stderr standard error output;

& 2>&1 means that the standard error output is redirected to the standard output stdout.

# The meaning of the sentence is that the standard output redirects to the empty device file, which means no output of any information to the terminal, standard error output redirection, etc.

Same as standard output, the standard error output is also redirected to an empty device file because the standard output was previously redirected to an empty device

Thing

    • Command > File 2>file differs from command > file2>&1

1,command >file 2>file meaning

# indicates the standard output information generated by the command, and the incorrect output information is sent to file . But file will be opened two times, and

StdOut and stderr will cover each other, which is equivalent to using FD1 and FD2 two simultaneously to seize the file of the pipeline.

2,command >file 2>&1 meaning

# indicates that the stdout is sent directly to file, stderr inherits the FD1 pipeline, and then is sent to file, at this time,file Only be opened once, also only

used a pipe FD1, which includes all the contents of stdout and stderr .

from IO efficiency, the efficiency of the previous command is less efficient than the latter, so when writing a shell script, we often use

Command > file 2>&1 such a notation.


This article is from "Tornado" blog, please make sure to keep this source http://ruilong.blog.51cto.com/4043170/1763289

Crontab Common/dev/null 2>&1 detailed

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.