there are many times in Linux where redirects are used to do some work. Let's talk about my understanding of redirection. Welcome to the slot
1,0< or < indicates that the standard input code is 0 or stdin
2, 1> indicates that the standard output code is 1 or stdout
3, 2> indicates an error output code of 2 or stderr
Standard output:
> or 1> output redirected to a file or device overwriting the original file
>! Force Overwrite
>> Append
OutputREDIRECT I'm not going to give you a good idea.
Standard input:
0 < or < input directed input redirection is used to change the input of the command, followed by the specified input, preceded by the file name
0<< or << append input redirection followed by string to indicate "end of input" or end with Ctrl+d
Example:
Example Explanation:
content redirection of standard input for cat receive keyboard output to the Test.txt file
Some students may not understand how cat can receive the standard input stream let's look at the definition of cat
Everyone should understand now .
Error Output:
2> Error Redirection: Entering the error message into a file behind it will delete the contents of the file .
2>> Error Append redirect: Appends the error message to the file in the back and does not delete the contents of the original file
Example:
Ehco "Hello World" 1>test1.txt 2>&1
Example Explanation: Redirect "Hello World" directly to Test1.txt if the command is correct without errors
if the command error, such as Ech "Hello World" command, error message will be input to test In 1.txt
Everyone must have a problem with this 2>&1.
The standard error output &1 for 2> represents the Test1.txt reference that the standard output opens
still do not understand, can refer to53507530
what they have in common is the direction of the arrows indicating the flow of data
About redirection > 1> 2>&1 >> in Linux