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.