Commands for Linux 2

Source: Internet
Author: User
Tags first string switches

Command VI to enter VI FileName: Opens or creates a new file and places the cursor at the beginning of the first VI +n FileName: Opens the file and places the cursor at the beginning of nth line VI + FileName: Opens the file and places the cursor at the last beginning of the line VI +/pattern filen Ame: Opens the file and places the cursor at the first string matching the pattern vi-r filename: A system crash occurred last time you were editing with VI, restore filename VI filename....filename: Open multiple files, edit them sequentially Move Cursor Class command h: Move Cursor left one character   L: Cursor Right one character   space: Cursor moves right one character   Backspace: Cursor moves left one character   K or ctrl+p: Move cursor up line   J or Ctrl +n: Move the cursor down one line   Enter: Move the cursor down a line   W or w: Move the cursor to the beginning of a word to the head   B or B: Move the cursor one word to the top   E or E: The cursor moves one word to the end of the word  ): The cursor moves to the end of the sentence   (: Cursor moves to the beginning of the sentence  }: The cursor moves to the start of the paragraph   {: Cursor moves to end of paragraph   NG: Cursor moves to nth line   n+: cursor moves down n lines   N: Cursor moves n lines   n$: Cursor moves to nth line end   H : The cursor moves to the top row of the screen   M: The cursor moves to the middle of the screen line   L: The cursor moves to the last line of the screen   0: (note is the number 0) the cursor moves to the current beginning   $: Cursor moves to the current line End screen tumbling class command   Ctrl+u: Turn the file to the top half screen   ctrl+d: Half screen to the end of the file   ctrl+f: Flip a screen to the end of the file   ctrl+b; flip one screen to file   NZ: Roll line N to the top of the screen, and roll the current line to the top of the screen when n is not specified. Insert Text Class command   I: Before the cursor   I: At the beginning of the line   A: After the cursor   A: At the end of the current row   O: A new line below the current line   O: New line above the current line   R: replace the current character   R: Replaces the current character and its characters until you press ESC   s: Starts at the current cursor position and replaces the specified number of characters with the input text   s: Deletes the specified number of lines and replaces them with the text entered   NCW or NCW: Modify the specified number of words   NCC: Modify the specified number of row Delete commands   NDW or NDW: Delete the n-1 characters at the beginning and after the cursor   do: Delete to the beginning of the line   d$: Cut to end of line   NDD: Delete the current line and its subsequent n-1 lines   x or x: Delete one character, x after deleting the cursor, and x before deleting the cursor   CTRL+U: Delete the text search and replace command you entered under Input mode  / Pattern: From the beginning of the cursor to the end of the file search pattern ? Pattern: Search from the beginning of the cursor to the top of the file pattern  N: Repeat the previous search command in the same direction   N: Repeat the last search command in the opposite direction  : s/p1/p2/g: Replace all P1 in the current line with P2  : n1,n2s/p1/p2/g: N1 overrides all N2 in the P1 to P2 line  : g/p1/s//p2/g: Replace all P1 in the file with P2 Option settings   All: Lists all option settings   term: Set terminal type   Ignorance: Ignore case in search   list: Show tab stop (Ctrl+i) and end of line flag ($)   Number: Display line number   Report: Displays the amount modified by the line-oriented command   terse: Displays a short warning message   warn: Displays no write information if the current file is not saved when you go to another file   Nomagic: Allows the use of special characters without "\" in the search mode   Nowrapscan: Prevent VI from reaching the end of the file and starting at the other end   MESG: Allow VI to display information that other users write to their terminal Last line command  : N1,N2 CO N3: Copy the contents of the N1 line to the N2 line under the N3 line  : n1,n2 m N3: Move the contents of the N1 line to the N2 line down to the N3 line  : N1,n2 D : Delete the contents of the N1 line to the N2 line.  : w: Save current file  : E filename: Open file filename for edit  : x: Save current file and exit  : Q: Exit vi : q! : Do not save the file and Exit VI :!command: Execute shell command command : n1,n2 w!command: Input and execute the contents of N1 line to N2 line in the file as command, if no n1,n2 is specified, is the input of the entire file content as command  : r!command: Put the command's output to the current line register operation   "? Nyy: Saves the contents of the current row and its next n rows to the register?" , where? is a letter, n is a number   "? NYW: Saves the current line and its next n characters to the register? , where? is a letter, n is a number   "? NYL: Saves the current line and its next n characters to the register? , where? is a letter, n is a number   "? P: Take out the register? and place it at the cursor position. Over here? can be a letter or a number   NDD: Deletes the current line and its total n lines of text, and places the deleted item in the 1th Delete register. Use of VI--------------------------------------------------------------------------------one, insert text   ┌──┬────────────┐ │ Command │ Description │ ├──┼────────────┤ │i│ insert text match either in the current word │ ├──┼────────────┤ │ I│ inserts text at the beginning of the line │ ├──┼────────────┤ │a│ add text after the current character │ ├──┼────────────┤ │a│ add text at the end of the line │  ├──┼────────────┤ │o│ insert a blank line after the current line │ ├──┼────────────┤ │o│ insert a blank line before the current line │ ├──┼────────────┤&nbsp ; │r│ input text in │ └──┴────────────┘  Two, move cursor  ┌─────┬───────────┐ │ command │ description │ ├─────┼─ ──────────┤ │j or DOWN ARROW │ Move down one line │ ├─────┼───────────┤ │k or up ARROW │ move up one line │ ├─────┼───────────┤ │h or left arrow │ Move left one character │ ├─────┼───────────┤ │l or right arrow │ move right one character │ ├─────┼───────────┤ │w│ one word to the right │&n Bsp ├─────┼───────────┤ │w│ right shifts a space-delimited word │ ├─────┼───────────┤ │b│ one word to the left │ ├─────┼───────── ──┤ │b│ left a space-delimited word │ ├─────┼───────────┤ │0│ move to the beginning of the line │ │ctrl-f│ page forward │ ├── ───┼───────────┤ │ctrl-b│ back page │ ├─────┼───────────┤ │ng│ to nth row │ ├─────┼───────── ──┤ │g│ to the last line │ └─────┴───────────┘  three, replace text  ┌─────┬──────┐ │ command │ description │ ├─── ──┼──────┤ │$│ to │ ├─────┼──────┤ │ (│ to the beginning of the sentence │ ├─────┼──────┤ │) │ to the end of the sentence │&nbs P ├─────┼──────┤ │{│ to the beginning of the paragraph │ ├─────┼──────┤ │}│ to the end of the paragraph │ └─────┴──────┘ four, delete the text  ┌───┬─── ────────┐ │ Command │ Description │ ├───┼───────────┤ │r│ Replace a character │ ├───┼───────────┤ │c│ modify the text until you press ESC │&NB Sp ├───┼───────────┤ │cw│ Modify the next word │ ├───┼───────────┤ │cnw│ modify the next n words │ └───┴───────────┘&nbs P V. Text Editor  ┌──┬──────────────────────┐ │ Temple │ Description │ ├──┼──────────────────────┤ │yy│ will be a Text moves to the default buffer │ ├──┼──────────────────────┤ │yn│ moves the next word into the default buffer │ ├──┼─────────────────── ───┤ │ynw│ moves the following n words into the default buffer │ ├──┼──────────────────────┤ │p│ if the default buffer contains a line of text, the current │ ││ line     Insert a blank line wells the sound │ ││ in the default buffer into this line, and if the default buffer contains │ ││ multiple words, paste the words to the right of the cursor. │ ├──┼──────────────────────┤ │p│ If the default buffer contains one line of text, a blank line is inserted before the current │ ││ line wells the inner │ ││ of the default buffer is pasted into In this line, if the default buffer contains │ ││ multiple words, paste the words to the left of the cursor │ └──┴──────────────────────┘  six, save exit  ┌───────────           ┬───────────────┐ │ Command │ Description  │ ├───────────┼───────────────┤ │zz│ Save and exit │ ├───────────┼───────────────┤ │:w filename│ Write file │ ├───────────┼───────────────┤ │:w│ write to file │ ├────────          ───┼───────────────┤ │:x│ Save (if the current file has been modified) and exit │ ├───────────┼───────────────┤ │:q! │ do not save files, exit │ ├───────────┼───────────────┤ │:q│ exit Vi│vi commonly used Skills VI command can be said to be the most in the Unix/linux world Commonly used to edit the command of the file, but because its command set a large number of people are not accustomed to use it, in fact, you only need to master the basic commands, and then use the flexibility, you will find its advantages, and will gradually like to use this method. This article is intended to introduce some of the most common commands and advanced application techniques for VI. First, the basic command introduction----1. Cursor commands K, J, H, l--up, down, left, and right cursor move commands. Although you can use the 4 cursor keys on the right side of the keyboard in Linux, it is useful to remember these 4 commands. These 4 keys are the basic positions that the right hand places on the keyboard.   ng--jump command. n is the number of rows, and the command immediately causes the cursor to jump to the specified line.   ctrl+g--the number of rows and columns in the cursor location report.   W, b--causes the cursor to skip forward or backward through a word.  ----2. Edit Commands   I, a, r--insert character commands (I=insert, A=append, R=replace) before, after, and where the cursor is located.   CW, dw--Change (displace)/delete the command (C=change, d=delete) of the word where the cursor is located.   x, d$, dd--delete a character, delete all the characters at the end of the line, and delete the entire line of the command.  ----3. Find commands  ----/STRING, string--the command to find the appropriate string from the location of the cursor, either backwards or forwards.  ----4. Copy copy command  ----yy, p--copy a line to the Clipboard or remove the contents from the Clipboard. Second, common problems and application skills----1. In a new file, read the contents of the/etc/passwd and remove the user name section.  ----VI file ----: R/etc/passwd reads/etc/passwd ----:%s/:.*//g Delete/etc/in open file All parts of the passwd that follow the user name, starting with a colon until the end of the line.  ----You can also read the contents of the file after the specified line number, such as using the command ": 3r/etc/passwd" to start reading all the contents of/etc/passwd from the 3rd line of the new file.  ----We can also use the following method to delete all empty lines in the file and comment lines starting with #.  ----#cat Squid.conf.default | Grep-v ^$ | Grep-v ^#----2. When you open a file to edit it is not known that the user logged in to the file does not have permission to write, you need to save the changes to the temporary file.  ----VI file ----: w/TMP/1 Save any changes you have made, or you can save some of these changes to a temporary file, such as simply saving the contents of the 20th to 59th row to a file/tmp/1, we can type the following command.  ----VI file ----: 20,59W/TMP/1----3. Edit a file with VI, but you need to delete the contents of the large segment.  ----First Use the edit command "VI file" to open the file, then move the cursor to the line you want to delete, press Ctrl+g to display the line number, and then press ctrl+g at the end to display the line number at the end of the file.  ----: 23,1045d assumes that 2 times the line number is 23 and 1045, the content of this period is deleted, you can also use the MA, MB command in the start and end rows to be deleted, and then remove it with the ": A,BD" command. ----4. Add strings at the beginning or end of the line or lines of the entire file.  ----VI file ----: 3, $s/^/some string/insert "Some str at the beginning of the first line of the file to the end of the last lineing ".  ----:%s/$/some string/g Add "some string" at the end of each line of the file.  ----:%s/string1/string2/g Replace "string1" into "string2" throughout the file.  ----: 3,7s/string1/string2/only Replace "string1" in line 3rd through 7th in the file with "string2".  ----NOTE: where S is substitute,% for all rows and g for global. ----5. Edit 2 files Simultaneously, copy the text from one file and paste it into another file.  ----VI file1 file2 ----YY Copy the line at the cursor of file 1  ----: n switches to File 2 (n=next)  ----p Pastes the copied row at the cursor of file 2   ----: N switches back to file 1----6. Replace the path in the file.  ----Use the command ":%s#/usr/bin#/bin#g" to change all the paths in the file/usr/bin to/bin. You can also use the command ":%s//usr/bin//bin/g" Implementation, where "" is an escape character, indicating that subsequent "/" characters are characters that have actual meaning, not delimited

Command 2 for Linux

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.