1.Output Redirection
Linux The default input is the keyboard, and the output is the monitor. You can use redirection to change these settings. For example , when using the WC command to manually enter a text to calculate the number of characters, you can directly put a written file with '<' point to this command, You can directly count the number of characters in this file.
STDOUT(standard output) and STDERR(standard error) can be redirected to a file
Command Operation Symbols file name
Supported operational symbols include:
> put STDOUT redirect to file
,etc under the passwd file,the app does not have a passwd file, the two redirects to export them to the file ls.txt , Only the wrong one is left after the carriage return. Then we look at the Ls.txt file and find the correct standard output inside
650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M01/9D/31/wKiom1l7HD6A-pzFAABBVe87cYw610.png "style=" float : none; "title=" Image001.png "alt=" Wkiom1l7hd6a-pzfaabbve87cyw610.png "/>
2> put STDERR redirect to file
Similarly, the use of 2> will be displayed correctly, the error output to the Ls.txt file.
650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M01/9D/31/wKioL1l7HD7RtIMpAAAiHSa4LwQ794.png "style=" float : none; "title=" Image002.png "alt=" Wkiol1l7hd7rtimpaaaihsa4lwq794.png "/>
&> redirect all output to file (or > 2>&1 )
, both methods input the correct error into the file.
650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M02/9D/31/wKiom1l7HD_iHfEGAABF7S9YhNs265.png "style=" float : none; "title=" Image003.png "alt=" Wkiom1l7hd_ihfegaabf7s9yhns265.png "/>
It is important to note that using > overrides the file contents by default.
Use set-c prevents content from being overwritten by existing files , but can be appended
>> On the basis of the original content, Append Content
>|file Force Overwrite
Set +c Allow overwrite
650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M00/9D/31/wKioL1l7HD-SF8kxAACB3zO9L3E282.png "style=" float : none; "title=" Image004.png "alt=" Wkiol1l7hd-sf8kxaacb3zo9l3e282.png "/>
You can also direct output and errors to different locations at one time, respectively
650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M02/9D/31/wKioL1l7HD_yf8jZAAAr9a2f3bM979.png "style=" float : none; "title=" Image005.png "alt=" Wkiol1l7hd_yf8jzaaar9a2f3bm979.png "/>
, directed to the Right.txt and error.txt files, respectively.
2.trConvert and delete
TR [OPTION] ... SET1 [SET2]
650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M01/9D/31/wKiom1l7HD-wPy61AAAcM6enSKA515.png "style=" float : none; "title=" Image006.png "alt=" Wkiom1l7hd-wpy61aaacm6enska515.png "/>
650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M00/9D/31/wKiom1l7HEDCeG6LAAAOaxAaUw8281.png "style=" float : none; "title=" Image007.png "alt=" Wkiom1l7hedceg6laaaoaxaauw8281.png "/>
(Enter the condition first, then enter the content you want to convert, enter a line of output line, until CTRL + C exit)
You can also use the redirect function, do not need input, enter a file directly, you can be replaced
650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M00/9D/31/wKioL1l7HECwrYCaAABeV6jHCqs988.png "style=" float : none; "title=" Image008.png "alt=" Wkiol1l7hecwrycaaabev6jhcqs988.png "/>
, you can output the. BASHRC content without having to re-BASHRC the contents of the. (This operation does not change the contents of the. bashrc.) )
- C – C--complement the complement of a character set (that is, nothing is removed)
, the characters except C are replaced by a.
650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M01/9D/31/wKiom1l7HECSUSYwAAATh10G-_U055.png "style=" float : none; "title=" Image009.png "alt=" Wkiom1l7hecsusywaaath10g-_u055.png "/>
- d --delete Delete all characters belonging to the first character set
, all of the files in the ABC have been removed.
650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M01/9D/31/wKioL1l7HEDwkxJxAABSutT6hys998.png "style=" float : none; "title=" Image010.png "alt=" Wkiol1l7hedwkxjxaabsutt6hys998.png "/>
- s --squeeze-repeats to remove consecutive repetitions of characters into one character
650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M02/9D/31/wKiom1l7HEHhST8yAAAhnCmEAbY352.png "style=" float : none; "title=" Image011.png "alt=" Wkiom1l7hehhst8yaaahncmeaby352.png "/>
, turn the repeating ABC into one, and the rest of the repeating letters do not move.
- T --truncate-set1 converts the character of the first character set to the second character set (no substitution is made on the corresponding one)
The corresponding character
[: Alnum:] : Letters and Numbers
[: Alpha:] : Letters
[: Cntrl:] : Control (non-printing) characters
[:d Igit:] : Digital
[: Graph:] : Graphic characters
[: Lower:] : Lowercase Letters
[:p rint:] : Printable characters
[:p UNCT:] : Punctuation
[: Space:] : white space characters
[: Upper:] : Uppercase Letters
[: Xdigit:] : Hexadecimal characters
3.Import from FileStdin
in the same way, we can use < to redirect the standard input Stdin
Some commands can accept import from a file Stdin
tr ' A-Z ' A-Z ' </etc/issue This command converts lowercase characters in /etc/issue to uppercase characters.
tr–d ABC </etc/fstab This command removes any characters from all of the ABC in the Fstab file (these two functions have been used above)
cat> file can write content to a file
650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M01/9D/31/wKioL1l7HEGRBxDnAAAdNAiVn2I739.png "style=" float : none; "title=" Image012.png "alt=" Wkiol1l7hegrbxdnaaadnaivn2i739.png "/>
Press ctrl+d or Ctrl + C to leave, you can use the file instead of the keyboard input
<< terminating words
You can edit it as you wish, until a line has only that terminating word, and you exit the edit and send the above content to the file.
650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M02/9D/31/wKiom1l7HEHy1nDfAAAae-JSrM8424.png "style=" float : none; "title=" Image013.png "alt=" Wkiom1l7hehy1ndfaaaae-jsrm8424.png "/>
Until the last act! Automatically exits when the
Cat > Filea < Fileb
650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M02/9D/31/wKioL1l7HEHweHfBAAAZAQC0HL0930.png "style=" float : none; "title=" Image014.png "alt=" Wkiol1l7hehwehfbaaazaqc0hl0930.png "/>
to write the contents of the Text.txt to file.txt
Again, we can import the file into the message and send it in this way.
( the code for sending the message is the mail-s " message name " that you want to send to, and then you enter the content and use ctrl+d Exit )
650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M00/9D/31/wKiom1l7HEKwpC15AAAbopQFyhw790.png "style=" float : none; "title=" Image015.png "alt=" Wkiom1l7hekwpc15aaabopqfyhw790.png "/>
Now we will Text.txt This file is written to the message and sent:
650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M00/9D/31/wKioL1l7HELQ2NuwAAC3KMFavzQ386.png "style=" float : none; "title=" Image016.png "alt=" Wkiol1l7helq2nuwaac3kmfavzq386.png "/>
, login magedu user, enter mail to view the mail, found that the message received is text.txt letter. (Enter quit after reading )
4.Piping
pipe (using symbols " | "representation" is used to connect commands
650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M02/9D/31/wKioL1l7HEKRVNasAAAJIpJq6Yc245.png "style=" float : none; "title=" Image017.png "alt=" Wkiol1l7hekrvnasaaajipjq6yc245.png "/>
, Pass the 1+2 to the calculator and draw the result
Command 1 | Command 2 | Command 3 | ... .. Send STDOUT of command 1 to STDIN of command 2, STDOUT of command 2 to command 3 The STDIN.
650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M01/9D/31/wKiom1l7HEPiOiPhAACCF0Fmjt8642.png "style=" float : none; "title=" Image018.png "alt=" Wkiom1l7hepioiphaaccf0fmjt8642.png "/>
, Will | Used in conjunction with tr to turn all the repeating spaces into a single space.
then continue to use | and grep command (which will be discussed later) query /boot that line
650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M01/9D/31/wKioL1l7HEPTcdKPAACXoTZdWJs441.png "style=" float : none; "title=" Image019.png "alt=" Wkiol1l7heptcdkpaacxotzdwjs441.png "/>
| only correct results can be redirected to the next command
using 2>&1 | or |& can redirect all results
5.REDIRECT to multiple targetsTee
command 1 | tee [ -A] file name | command 2
Save the STDOUT of command 1 in the file as input to command 2
-A append
Use:
save output at different stages
Troubleshooting Complex Pipelines
view and record output at the same time
This article is from the "ty_endless" blog, make sure to keep this source http://tyendless.blog.51cto.com/12435756/1951819
Redirect, pipe--linux basic commands (6)