You can often see them in a scheduled task. Examples of our company's planning tasks include:
*/2 * * * * * root cd/opt/xxxx/test_s1/html/xxxx/admin; PHP index.php task Testone >/dev/null2>&1*/2 * * * * Root cd/opt/xxxx/test _s1/html/xxxx/admin; PHP index.php task testtwo >/dev/null2>&1
For & 1 It is more accurate to say file descriptor 1, while 1 identifies standard output, stdout.
For 2, indicates a standard error, stderr.
2>&1 means redirecting standard errors to standard output. Here the standard output has been redirected to/dev/null. Then the standard error will be output to/dev/null
You can think of/dev/null as a "black hole". It is equivalent to a write-only file. All content written to it will be lost forever. While trying to read from it, nothing can be read.
Occasionally you can add & at the end of the command, indicating that the program is executed in the background.
Why 2>&1 to write in the back?
index.php task Testone >/dev/null2>&1
We can understand that the left side is the standard output, OK, now the standard output is directly input into/dev/null, and 2>&1 is to redirect the standard error to the standard output, so when the program generates an error, the error is equivalent to the left side, The left side is still entered into the/dev/null.
Can be understood as, if written in the middle, that will be the partition standard output of the specified output file
You can use
LS 2>1 test, will not report the error of No 2 file, but will output an empty file 1;
ls xxx 2>1 test, no xxx This file error output to 1;
ls xxx 2>&1 test, will not generate 1 of this file, but the error ran to the standard output;
ls xxx >out.txt 2>&1, actually can be replaced with ls xxx 1>out.txt 2>&1; redirect symbol > default is 1, error and output are uploaded to OUT.txt.
What "2>&1" means in the Linux shell