I know you have to use …
php lots_of_errors.php > temp.txt 2>&1
…if you want to redirect the error logs into a temp.txt
- 1 = standard output (where programs print normal output)
- 2 = standard error (where programs print errors)
You use &1 to indicate that it’s a file descriptor and not a file but why don’t you use & sign in front of 2 like &2>&1 then?
Because the
&symbol is how the shell knows you are redirecting to a file descriptor instead of a file. That is, the lefthand-side (LHS) of the>operator is always a file descriptor, but the RHS is generally a filename. So this:Would redirect file descriptor 2 to a filenamed “1”. The amperand is how the shell knows you mean “file descriptor 1”: