Changes between Version 5 and Version 6 of ubuntuinstall


Ignore:
Timestamp:
Nov 17, 2016, 5:58:34 AM (8 years ago)
Author:
admin
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • ubuntuinstall

    v5 v6  
    206206}}}
    207207
     208=== File Editing ===
     209
     210The vi editor is installed on almost every Unix. Linux will very often install vim (vi
     211improved) which is similar. Every system administrator should know vi(m), because it is
     212an easy tool to solve problems.
     213
     214'''vi Commands and Tips'''
     215{{{
     216Open: 
     217
     218vi filename             (fn=filename)
     219vi -r filename          Recover a file from a crashed session
     220vi + filename           Place the cursor on last line of file.
     221vi +n filename          Place the cursor on line "n" of file.
     222vi +/pat filename       Place cursor on line with first occurrence of "pat"tern
     223
     224Close:
     225
     226:w                      Write the file to disk. Don't exit.
     227:w!                     Write the file to disk even if read/only.
     228:wq                     Write the file to disk and exit.
     229:wq!                    Write the file to disk even if read/only and quit.
     230:q                      Quit the file (only if no changes).
     231:q!                     Quit the file even if changes.
     232
     233Movement:
     234
     235A                       Move to end of line, change to insert mode.
     236h                       Move 1 space backwards (back/left arrow).
     237j                       Move down 1 line (down arrow).
     238k                       Move up 1 line (up arrow).
     239l                       Move 1 space forwards (forward/right arrow)
     240w                       Move cursor to start of next word.
     241W                       Same as "w".
     242b                       Move cursor to start of previous word.
     243B                       Same as "b".
     244:n                      Go to line number "n" in the file.
     245
     246Editing:
     247
     248i                       Enter in to input mode.
     249o                       Add a line below cursor and enter in to input mode.
     250x                       Delete character (del key in some cases).
     251D                       Delete line from right of cursor to end of line.
     252dd                      Delete entire line.
     253u                       Undo last edit or restore current line.
     254yy                      Yank current line.
     255p                       Put yanked text before the cursor.
     256
     257Searching:
     258
     259/pattern               Search for "pattern" in the file going forwards.
     260?pattern               Search for "pattern" in the file going backwards.
     261n                      Find the next occurrence of pattern found forwards.
     262N                      Find next occurrence of pattern found backwards.
     263
     264Copy/Cut and Paste
     265<NUM>yyp               Copy n lines to buffer, paste below cursor
     266<NUM>yyP               Copy n lines to buffer, paste above cursor
     267<NUM>ddp               Cut n lines and copy to buffer, paste below cursor
     268<NUM>ddP               Cut n lines and copy to buffer, paste above cursor
     269}}}
     270 
     271==== Practice Using vi ====
     272
     273'''Remember The vi editor uses "modes"'''
     274
     275The easiest thing to do if you get confused in vi is to press the ESCape key a couple of times and start over with what you were doing. Log in to your VM and...
     276{{{
     277$ cd
     278$ vi temp.txt
     279}}}
     280vi wil create the file “temp.txt” for you. Press the "i" key to switch to input mode.
     281{{{
     282    Type something like, "VI is great! I think I'll be using vi from now on instead of Word”
     283    Press <ENTER> to add lines.
     284    Type some more text
     285}}}
     286Save the file that you are in. To do this do:
     287
     288Press the ESCape key for command mode Type “:wq” then hit Enter to save and quit the file (notice the “:” before the “wq”).
     289
     290Copy a large file to your home directory so that you can play around with some more vi commands. We'll copy over your /etc/sysctl.conf file for this exercise. To do this do:
     291{{{
     292$ cd
     293$ cp /etc/sysctl.conf sysctl.conf.bak
     294}}}
     295Edit the file, but let's start at the bottom of the file:
     296{{{
     297$ vi + sysctl.conf.bak
     298}}}
     299Go to the first line of the file. Notice the colon (“:”) before the “1”.
     300{{{
     301:1 <ENTER>
     302}}}
     303Go to line 10, add a new line, and add in some text:
     304{{{
     305:10 <ENTER>
     306Press the “o” key
     307}}}
     308Add the following text:
     309{{{
     310##
     311## A sample comment
     312##
     313}}}
     314Delete the three lines you just created:
     315
     316    Move to the first line of new text
     317    Press the ESCape key
     318    Press “dd” to delete a line, repeat until the text is gone
     319
     320Save the file, but don’t exit.
     321{{{
     322    :w
     323    press <ENTER>
     324}}}
     325Practice copying and pasting text.
     326
     327Go to line 12, copy 3 lines of text, go to the bottom of the file, place the text there:
     328{{{
     329    ESC         (go to command mode)
     330    :12 <ENTER> (go to line 12 of the file)
     331    3yy         (“yank” 3 lines of text and place in copy buffer)
     332    G           (go to the end of the file)
     333    p           (place the contents of the copy buffer here)   
     334}}}
     335If want to undo this you would type (in command mode):
     336{{{
     337    u
     338}}}
     339Go to the top of the file, replace all occurrences of “ipv4” with “ipv6”, but prompt for each change:
     340{{{
     341    ESC
     342    :1 <ENTER>
     343    :%s/ipv4/ipv6/gc
     344}}}
     345Say “yes” or “no” to a few prompts then escape from this mode by pressing ctrl-c and .
     346
     347Go to line 1, search for “kernel”, move to the end of the line, add some text:
     348{{{
     349    ESC
     350    :1 <ENTER>
     351    /kernel
     352    SHIFT-A
     353    “text here”
     354    ESC
     355}}}
     356Now let’s exit from the file and not save the few changes we’ve made.
     357{{{
     358    :q! <ENTER>
     359}}}
     360
    208361=== Setting UP IP Addresses ===
    209362
     
    211364Get your IP address from the [wiki:ipallocation IP table]
    212365{{{
     366
    213367iface eth0 inet static
    214368