1, Linux standard input and output
The traditional Linux standard input and output devices are mainly keyboards and monitors, which are described in detail in the following table.
| linux standard input Output |
| device |
device file name |
file descriptor |
type |
symbol for |
| keyboard |
/dev/stdin |
0 (the default is the keyboard, which is the output of a file or other command 0 o'clock) |
standard input |
<< |
/tr> |
| monitor |
/dev/stdout |
1 (default is screen, 1 o'clock is file) |
standard output |
>> |
|
| Monitor |
/dev/stderr |
2 (default is screen, 2 o'clock is file) /td> |
standard error Output |
2> |
2>> |
Note: One of the > says: Cover the contents of the original document;
Two > that is >> : Append to the contents of the original file. 2. Linux output redirection
Output redirection: Changes the input source and the output location of the program running.
The main applicable methods are shown in the following table:
| Output redirection |
| Type |
Symbol |
Function |
| Standard output redirection |
Commands > Documents |
To overwrite the correct output of a command to a specified file or device |
| Commands >> Documents |
To output the correct output of a command to a specified file or device in an append manner |
| Standard Error Output redirection |
Error command 2> file |
To overwrite the error output of a command to a specified file or device |
| Error command 2>> file |
Outputs the error output of a command to a specified file or device in an append mode |
| Correct/error output is saved at the same time |
Command > File 2>&1 |
Save the correct output and error output of the command to the same file in the Overwrite mode |
| Command >> file 2>&1 |
Save the correct output and error output of the command to the same file in the Append mode |
| Commands &> Documents |
Save the correct output and error output of the command to the same file in the Overwrite mode |
| Commands &>> Documents |
Save the correct output and error output of the command to the same file in the Append mode |
| Command >> file 1 2> file 2 |
In append mode, save the correct output of the command in file 1, and overwrite the error output of the command to file 2. |
3. Input redirect
| Input redirection |
| Type |
Symbol |
Function |
| Standard input |
Command < file 1 |
command to input the contents of document 1 as standard |
| Identifier qualified input |
Commands << identifiers |
Command reads content from standard input until it encounters the identifier delimiter position |
| Input and output redirection |
Command < file 1 > file 2 |
command to use the contents of document 1 as standard input, file 2 as standard output |
(Content of reference: http://blog.csdn.net/cjfeii/article/details/10084343)