RHCE Study notes (4)

Source: Internet
Author: User

This section focuses on redirecting, piping, and vim editors


First look at the output redirection

1 > or > means to overwrite the correct information with the output redirect, 1>> or >> to indicate an additional redirect

2 > indicates that the error information is overwritten with the output redirect, and 2>> indicates that the additional error message is redirected

&> directs all information, right or wrong, to a file, and can use > AA 2>&1 or 2>AA 1>&2 format, but obviously the latter is more complex


As shown below, the correct information can be directed to AA for the first time, the second error message 1> cannot be directed past, the new content cannot be written after emptying the file, and the third time 2> directs the error message to AA

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/57/47/wKioL1SXnFyghH-4AAD-dG2Ento772.jpg "style=" float: none; "title=" 1.PNG "alt=" Wkiol1sxnfyghh-4aad-dg2ento772.jpg "/>


The example is that the beans use rsync to copy between the Apple server and Linux, and he writes both the failure and the success information to the same log file

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/57/49/wKiom1SXm7Sx-0cBAABqz0-KQxE928.jpg "style=" float: none; "title=" 2.PNG "alt=" Wkiom1sxm7sx-0cbaabqz0-kqxe928.jpg "/>


Next look at what the pipeline does, and he can pass the result of the previous command as input to the latter command. A very common use is to query with grep


Take a look at the following example, first create a new user beanxyz, pay attention to capitalization

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/57/49/wKiom1SXm7WiA1jSAABAxgfcx48296.jpg "style=" float: none; "title=" 3.PNG "alt=" Wkiom1sxm7wia1jsaabaxgfcx48296.jpg "/>


Copy the passwd file locally, and then execute the cat-n passwd | grep beanxyz, can see the user name found in lowercase

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/57/49/wKiom1SXm7qz10VKAAEaRhSu-RM801.jpg "style=" float: none; "title=" 4.PNG "alt=" Wkiom1sxm7qz10vkaaearhsu-rm801.jpg "/>


If I (ignore) is added, you can ignore the case and get two user information


650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/57/47/wKioL1SXnGSSRN0KAACYDEbKug0255.jpg "style=" float: none; "title=" 5.PNG "alt=" Wkiol1sxngssrn0kaacydebkug0255.jpg "/>


If you specify A3 (below 3 lines), B3 (3 rows above), you can also get data for several nearby rows


650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/57/47/wKioL1SXnGeSpLqqAAEnDmX4BD4239.jpg "style=" float: none; "title=" 6.PNG "alt=" Wkiol1sxngesplqqaaendmx4bd4239.jpg "/>


If you use-V, you can reverse-filter the number of rows except ' beanxyz '


650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/57/47/wKioL1SXnGrAssljAAFUmGUwcEQ739.jpg "style=" float: none; "title=" 7.PNG "alt=" Wkiol1sxngrassljaafumguwceq739.jpg "/>


Sometimes, if you need to save the data to a temporary file, you can use tee to write, if you want to append information, you can use the-a option

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/57/49/wKiom1SXm8qhmF4NAAJqDPyeYrY118.jpg "style=" float: none; "title=" 8.PNG "alt=" Wkiom1sxm8qhmf4naajqdpyeyry118.jpg "/>


Quiz: How do I get the data for line 11th to 20th in/etc/passwd?


Idea: First to get the first 20 rows of data, and then get the last 10 rows of data can be


650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/57/47/wKioL1SXnHmjJ_g6AAIs1NwguHA083.jpg "style=" float: none; "title=" 9.PNG "alt=" Wkiol1sxnhmjj_g6aais1nwguha083.jpg "/>


Next look at the use of the play vim.

First, look at how the line numbers are displayed in the Vim editor and enter them in a single file: Set number


650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/57/49/wKiom1SXm97z7TtbAANVOqndY4o794.jpg "style=" float: none; "title=" 10.PNG "alt=" Wkiom1sxm97z7ttbaanvoqndy4o794.jpg "/>


But once you exit, this feature is gone. Users can change the. vimrc file under the home directory to add a message, and all text files under that user can be opened with Vim to display line numbers.

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/57/47/wKioL1SXnIeSF_ifAABunBbnWHo201.jpg "style=" float: none; "title=" 11.PNG "alt=" Wkiol1sxniesf_ifaabunbbnwho201.jpg "/>


Similarly, if you want the feature to be effective for all users, you can modify the/ETC/VIMRC file directly

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/57/49/wKiom1SXm-TTau5ZAAG034opa1k807.jpg "style=" float: none; "title=" 12.PNG "alt=" Wkiom1sxm-ttau5zaag034opa1k807.jpg "/>


Open/etc/passwd to see the effect

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/57/47/wKioL1SXnJzypBjqAANmUEicyd4997.jpg "style=" float: none; "title=" 13.PNG "alt=" Wkiol1sxnjzypbjqaanmueicyd4997.jpg "/>


Let's take a look at what common commands vim has. Simply put, VIM has 3 modes, insert mode, command line mode and last line mode.


Mode switching:


From normal into the insert mode, you can enter by I,o,a or i,o,a, the difference is that the position of the insertion cursor is different, I think I have to remember most of the time enough


From insert exit to normal, press ESC


Enter the last line mode from normal, you can enter: wq! Force a search to exit or/make a keyword



Each mode has a number of individual command combinations. Here are some of the most common, basically will be used after the ordinary text editing should be no problem


Normal Mode:


Delete the character of the cursor and press X to

Copy the line that contains the cursor yy

Copy the word where the cursor is YW

The line where the clipping is located DD

Paste P

Replace character R and enter the character you want to replace

Undo Previous Step U


The above actions are for lines or words, not flexible enough, if you want to copy and paste a paragraph how to do? Can be manipulated in visual mode.


Enter V, then select a large piece of content by the cursor, press Y to copy, press p to paste



Insert mode:


If you can use the mouse, this and ordinary text editing basically no difference, you can change, delete, add data, copy and paste more easily can directly highlight a bunch of characters and then click the wheel on the line

Undo the previous action Ctrl+u




In the last line mode:

Search keyword, input/keyword, can be the next match by pressing N or N

Force Save: w!

Forced exit: q!

Force Save exit: wq!

Save: Saveas/path

Split screen: Split, which can then be toggled via Ctrl+w

Turn off split screen: close

Jump to a line: number can jump to the corresponding line




Finally, if you want to know more commands, you can learn by Vimtutor.

This article is from the "Mapo Tofu" blog, please be sure to keep this source http://beanxyz.blog.51cto.com/5570417/1592526

RHCE Study notes (4)

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.