Linux input/Output REDIRECT usage __linux

Source: Internet
Author: User
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)


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.