redirect
$echo "Test Redirect" > Temp.txt--Writes the output to the Temp.txt,temp.txt file is first emptied.
$echo "Test redirect Second" > Temp.txt-Append the output to the temp.txt.
File descriptor
0--stdin Standard Input
1--stdout Standard output
2--stderr standard Error
File descriptors and redirects
$xx 2>err.txt--Output the error message to the Err.txt file.
$ls 1>out.txt--the console information output to out.txt,1 and 2 can be specified at the same time.
$xx >output.txt 2>&1--The error message is also output to output.txt, because > is equivalent to 1>, which is the standard output. 2>&1, redirect the error to standard output.
$xx &> output.txt--&> indicates that both standard output and errors are output to the destination file.
$xx 2>/dev/null--/dev/null is a special file, the content redirected to it will be discarded.
Retain original copy of data after redirection
$echo T1>t1.txt
$echo T2>t2.txt
$chmod T1
$cat t* | Tee-a Test_tee.txt | Cat-n--Use the tee command to read the standard input and save the standard output to the specified file, after which you can continue to use the pipeline.
Note: Tee-a,a:append. Cat-n,n:number.
File redirection to Input
$cat <<eof>>log.txt
The input between the $EOF--eof is output to Log.txt.
Create a custom file descriptor
$echo Test line > Input.txt
EXEC 3<input.txt
Cat-n <&3--Read the input by a file descriptor, read only once, and read again the file descriptor needs to be reassigned.
Shell script Programming {2} per day