I/O redirection

Source: Internet
Author: User

Program: Instruction + Data

Data entry: Interactive, file, process

Data output: Monitors, files, processes

Standard input (stdin): 0, keyboard

Standard Output (stdout): 1, monitor

Error Output (stderr): 2, monitor

The normal output and error output are two different data streams;

Redirect:

Output redirection: , >>

COMMAND> new_position: overwrite redirect, will empty the file data ;

CAUTION: hazardous operation; To turn off this feature, you can use the set-c " , the opposite action is "set+c"

COMMAND>> new_position: Follow-up orientation , new data will be appended to the original file data;

Error Output redirection: 2>, 2>>

Command2> Err_output Overwrite the contents of the file

command2>> err_output appended to file data


Two output data streams are also directed :

Method One:

COMMAND> out_file 2>&1

COMMAND>> out_file 2>&1


Method Two:

COMMAND&> out_file

COMMAND&>> out_file


Enter redirection:

command< new_in

TR Command :

Tr[option] ... SET1 [SET2]

put the output data in the each character in the SET1 is correspondingly replaced by each character of the SET2;

-D: Deletes the data that appears in the input stream that belong to each corresponding character of the SET1;


COMMAND << EOF [EOF represents end of File]

[[email protected] tmp]# cat << EOF >abc.txt> I am lx> Hello world> eof> eof[[email protected] tmp]# Cat abc.txt I am lxhello worldeof


REDIRECT content output from input redirection to in the Abc.txt file, EOF can be substituted with any string, case-sensitive


Pipeline: |

put The output of COMMAND1 as the input of COMMAND2, and then the output of COMMAND2 as the input of COMMAND3, etc. .

command1| COMMAND2 | COMMAND3 | ...


Multi-Channel output:

command| Tee/path/to/somefile

Tee Command : The standard input is displayed in the standard output and saved to the file xx, if xx file does not exist is created, the existence will overwrite;

[-A]: append to the back of the file , rather than covering



This article is from the "xxlixin" blog, make sure to keep this source http://xxlixin1993.blog.51cto.com/9498220/1625961

I/O redirection

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.