Linux redirection and linux redirection
1. Two Methods of output redirection:
> Overwrite original file content
> Append write, which does not overwrite the content of the original file
2. Two redirection Methods
Incorrect command redirection 2> or 2> (incorrect command redirection> or and> there cannot be spaces on both sides)
Correct command redirection> or>
Frequently used:
The error PASSWORD command + correct command is saved to the same file:
Method 1: Command> file 2> & 1 (only one file is overwritten>)
Method 2: commands &> files (only one file is overwritten>)
Eg: ls/home/heyu> access. log 2> & 1
Ls &>/home/heyu
The error command and the correct command are saved to different files:
Command> Save the correct result file 2> Save the error result File
Eg: cd fjladjflaj> access. log 2> error. log
Input/Output redirection in Linux Shell environment, expressed by symbols <and>. 0, 1, and 2 indicate standard input, standard output, and standard error respectively.
1. redirect standard output to file: cat foo> foo.txt 2. redirection standard error to file cat foo 2> foo.txt 3. redirect standard output to standard error cat foo 1> & 24. redirect standard errors to standard output cat foo 2> & 15. redirection of standard output, standard errors to the same file cat foo> foo.txt 2> & 1 or cat foo &> foo.txt the first order is very important. First, redirect the standard output to the file, then output the standard error to the standard output, because the standard output has been redirected to the file, so the standard error and redirection to the file.
Ls 2> 1 will output an empty file 1;
Ls xxx 2> 1 no errors in the xxx file are output to file 1;
Ls xxx 2> & 1 does not generate the file 1, but the error is returned to the standard output;
Ls xxx> out.txt 2> & 1, which can be changed to ls xxx 1> out.txt 2> & 1; the redirection symbol> timeout is a error and the output is transmitted to out.txt.