Input and output redirection in the Shell environment

Source: Internet
Author: User

Input and output redirection in a Linux Shell environment, denoted by symbols < and >. 0, 1, and 2 represent standard inputs, standard outputs, and standard errors, respectively.

1. redirect standard output to file: Cat fo > foo.txt2. REDIRECT standard error to file cat fo 2> foo.txt3. REDIRECT standard output to standard error cat fo 1>&24. REDIRECT standard error to standard output cat fo 2& gt;&15. REDIRECT standard output, standard error to the same file cat fo > Fo.txt 2>&1 or cat foo &> Foo.txt the first order here is important, redirect the standard output to a file, and then output the standard error to the standard output, because the standard output has been redirected to the file, so the standard error is redirected to the file. >& Same as &> effect--------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------- --------

I used to see & 1, &2 such symbols, but I don't know what it means.

There are 12 file descriptors in the system, 0,1,2 is standard input, output and error. You can use file descriptors 3 to 9 arbitrarily

file File Descriptor
Input file--standard input 0
Output file-standard output 1
Error output file-standard error 2

Standard input: 0

The default is keyboard input, or it can be the output of a file or other command

Standard output: 1

The default is output to the terminal, you can also output to a file

Standard ERROR: 2

Command error message output, default output to terminal, can also output to file

If the file descriptor is not specifically specified, the command will use the default file descriptor, keyboard output, terminal output

After you enter a cmd, if no standard output or error output is specified, all output is displayed on the screen,

If the command is: cmd > result.out the command is equivalent to CMD 1>result.out, the standard output is redirected to the Result.out file, and the error output is displayed on the screen;

If the command is: cmd 2>result.out, the error output is redirected to the Result.out file, and the standard output is displayed on the screen;

If the command is: cmd >result.out 2>&1, both the standard output and the error output are redirected to the Result.out file, and there is no output on the screen.

Input and output redirection in the Shell environment

Related Article

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.