Linux redirection and linux redirection

Source: Internet
Author: User

Linux redirection and linux redirection

1. Two Methods of output redirection:

> Overwrite original file content

> Append write, which does not overwrite the content of the original file

2. Two redirection Methods

Incorrect command redirection 2> or 2> (incorrect command redirection> or and> there cannot be spaces on both sides)

Correct command redirection> or>

Frequently used:

The error PASSWORD command + correct command is saved to the same file:

Method 1: Command> file 2> & 1 (only one file is overwritten>)

Method 2: commands &> files (only one file is overwritten>)

Eg: ls/home/heyu> access. log 2> & 1

Ls &>/home/heyu

The error command and the correct command are saved to different files:

Command> Save the correct result file 2> Save the error result File

Eg: cd fjladjflaj> access. log 2> error. log

Input/Output redirection in Linux Shell environment, expressed by symbols <and>. 0, 1, and 2 indicate standard input, standard output, and standard error respectively.

1. redirect standard output to file: cat foo> foo.txt 2. redirection standard error to file cat foo 2> foo.txt 3. redirect standard output to standard error cat foo 1> & 24. redirect standard errors to standard output cat foo 2> & 15. redirection of standard output, standard errors to the same file cat foo> foo.txt 2> & 1 or cat foo &> foo.txt the first order is very important. First, redirect the standard output to the file, then output the standard error to the standard output, because the standard output has been redirected to the file, so the standard error and redirection to the file.

Ls 2> 1 will output an empty file 1;

Ls xxx 2> 1 no errors in the xxx file are output to file 1;

Ls xxx 2> & 1 does not generate the file 1, but the error is returned to the standard output;

Ls xxx> out.txt 2> & 1, which can be changed to ls xxx 1> out.txt 2> & 1; the redirection symbol> timeout is a error and the output is transmitted to out.txt.

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.