IO redirect,
In OS, each number in 0-9 represents a stream.
Three have been specified: [0: standard input stream], [1: Standard output stream], and [2: Error output stream]. The remaining are not yet specified.
Basic IO operations
Cmd> file redirects stdout to the file; cmd> file redirects stdout to the file (append); cmd 2> file redirects stderr to the file; cmd 2> file redirects stderr to the file (append); cat <> file opens file in read/write mode; cmd <file cmd command uses file as stdin; cmd <delimiter, read from stdin until the delimiter is encountered.
Advanced IO
& Operation on FD (File Descriptor)> & N copy the file descriptor
<& N the standard input is copied from the file descriptor n; <&-Disable the standard input (keyboard);> &-Disable the standard output; n <&-indicates that the n number is disabled; n> &-indicates that output n is disabled;
Cmd 2> & 1 is to copy the FD of the standard output stream to the error output, which is equivalent to: FD2 = FD1. The result is that the error output is redirected to the standard output.
Therefore:
Cmd> file 2> & 1 is to redirect the standard output to file (overwrite mode), and then put the error output content in the standard output, the final result is that the error output is redirected to the file.
Cmd> file 2> & 1 is to redirect the standard output to file (append mode), and then put the error output content in the standard output, the final result is that the error output is redirected to the file.