Special symbols:
Input redirection: The output of the previous input into the file in the back, will erase the original contents of the file.
Example:
[Email protected] kang]# echo ' Hello World ' > Test.txt
[email protected] kang]# cat Test.txt
Hello World
> Append output redirection: Append the previous output to the trailing end of the file, without erasing the original contents of the file.
Example:
[email protected] kang]# cat Test.txt
Hello World
Ming Kang
< input redirection: Input redirection is used to change the input of the command, followed by specifying the input, preceded by the file name.
Example:
[Email protected] kang]# Xargs-n 1 < test.txt
Hello
World
Ming
Kang
<< Append input redirection: followed by a string to indicate "input end" or ctrl+d to end the input
[email protected] kang]# cat >>test.txt<<eof
You are welcome
Eof
[email protected] kang]# cat Test.txt
Hello World
Ming Kang
You are welcome
2> Error Redirection: Entering the error message into a file behind it will delete the original contents of the file.
Example:
[[email protected] kang]# Echb ' ERROR ' 2> test.txt
[email protected] kang]# cat Test.txt
-bash:echb:command not found
2>> Error Append redirect: Appends the error message to the file behind it and does not delete the original contents of the file.
[Email protected] kang]# eco ' test ' 2>> test.txt
[email protected] kang]# cat Test.txt
-bash:echb:command not found
-bash:eco:command not found
Enter the correct and incorrect information, respectively, into different file methods:
[Email protected] kang]# echo ' Hello World ' >ok.txt 2>error.txt
[email protected] kang]# cat Ok.txt
Hello World
Put the correct and wrong information, enter the same file:
[[email protected] kang]# ech ' ERROR ' >>ok.txt 2>&1
[email protected] kang]# cat Ok.txt
Hello World
-bash:ech:command not found
Special character understanding of Linux (Sixth chapter)