IO redirection and piping on Linux-&> &>> 2> 2>> 2>&1 2>>&1 | Tee TR

Source: Internet
Author: User

IO redirection:

Output REDIRECT:>

features: Overwrite output

Output REDIRECT:>>

Features: Append output

# set-c

suppresses overwrite output redirection to existing files;

You can use the force overwrite output at this time: >|

# set +c

Turn off the above features

Error output stream redirection: 2> 2>> will only output the wrong information to the specified location

merge Normal output stream and error output stream:

(1) &>, &>>

(2) COMMAND >/path/to/somefile 2>&1

COMMAND >>/path/to/somefile 2>&1

[[email protected] tmp]# Ech "Next" > A.txt-bash:ech:command not found[[email protected] tmp]# ech "Next" > A.txt 2>&1[[email protected] tmp]# ech "Next" &> a.txt [[email protected] tmp]# Ech "Next" 2> a.txt

Special Equipment:/dev/null, representing empty

COMMAND >/dev/null: Represents all output information will not be displayed, go directly to the/dev/null inside

Use Demo:

[[email protected] tmp]# echo  "Hello"  > a.txt[[email protected] tmp ]# cat a.txt hello[[email protected] tmp]# echo  "Next"  >>  a.txt[[email protected] tmp]# cat a.txt hellonext[[email protected] tmp]#  ech  "Next"  > a.txt -bash: ech: command not found[[email  protected] tmp]# cat a.txt [[email protected] tmp]# ech  "Next"  2 > a.txt [[email protected] tmp]# cat a.txt -bash: ech: command  not found[[email protected] tmp]# ech  "Next"  &>> a.txt  [[email protected] tmp]# cat a.txt -bash: ech: command not  found-bash: ech: command not found[[email protected] tmp]# ech  "Next"  > /dev/null -bash: ech: command not found[[email protected] tmp]# ech  " Next " &> /dev/null


Enter redirection:

Enter redirect:<

Features: Overwrite input

Enter redirect:<<

Features: Append input

Use Demo:

1, [[email protected] tmp]# cat << EOF >a.txt> i> wish> nothing> but > the > best> for> yo  U>!> Eof[[email protected] tmp]# cat a.txt iwishnothingbut the bestforyou!2, [[email protected] tmp]# cat > A.txt << eof> l> o> v> e> eof[[email protected] tmp]# cat A.txt Love


TR command:

TR [OPTION] ... SET1 [SET2]

Converts the characters in the input data to the characters that appear in the SET1 definition, all the bits are converted to SET2 occurrences.

Usage 1:

TR SET1 SET2 </path/from/somefile

Usage 2:

Tr-d SET1 </path/from/somefile

Note: Do not modify the original file, only show it

[[email protected] tmp]# tr-d o < a.txt lve[[email protected] tmp]# cat a.txt love[[email protected] tmp]# tr "A-Z" "A -Z "< A.txt Love


Pipeline: A connection program that implements the output of the previous command directly after a program as an input data stream

COMMAND1 | COMMAND2 | COMMAND3 | ...

Converts the information in the first 6 lines of the/etc/passwd file into uppercase characters after output; [email protected] tmp]# Head-n 6/etc/passwd | Tr ' A-Z ' A-Z ' root:x:0:0:root:/root:/bin/bashbin:x:1:1:bin:/bin:/sbin/nologindaemon:x:2:2:daemon:/sbin:/sbin/ nologinadm:x:3:4:adm:/var/adm:/sbin/nologinlp:x:4:7:lp:/var/spool/lpd:/sbin/nologinsync:x:5:0:sync:/sbin:/bin/ SYNC

Tee command: Overwrites the results of the previous command to a file in a pipeline

[email protected] tmp]# Cat A.txt | Tee B.txtlove[[email protected] tmp]# cat B.txt Love




This article is from the "Wang Liming" blog, make sure to keep this source http://afterdawn.blog.51cto.com/7503144/1855782

IO redirection and piping on Linux-&> &>> 2> 2>> 2>&1 2>>&1 | Tee TR

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.