About redirection > 1> 2>&1 >> in Linux

Source: Internet
Author: User

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

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.