UNIX VI
UNIX VI
UNIX VI
UNIX command lines tend to be quite terse and are probably not terribly intuitive. Here is a list of the common UNIX commands you may used from time to time.
Command vi cp mv rm Variants Meaning Edit the specified file Make a copy of the specified file Rename (move) the specified file Delete a specified file Remove a directory and all files in it Remove a file, but ask first to confirm List the files in a directory List the files in order of creation List the files in reverse order of creation List files with extra information (eg date of modification, file permissions etc) Make a new directory (folder) Remove a specified directory Change to a subdirectory Change to the home directory Change up to a new directory Use vi h2o.com cp h2o.com test.com mv h2o.com h3o.com rm h3o.com rm r junk ls
A primer for vi
The built in editor on pretty much all UNIX machines (including MacOSX machines) is vi. It is pretty versatile and powerful although the commands are not immediately intuitive. To begin editing a file, issue the command: vi filename Here are some more common vi editing commands that you will come across. Note that upper and lower case commands have distinct meanings ie commands are case sensitive.
Initiating Input Mode i a O o #s r R cw C (same as c$) ESC Delete dw dd x Inserts before cursor Inserts after cursor Inserts before current line Inserts after current line Replaces # characters (# = number) Replaces a single character Replaces as many characters as are typed Replaces a word Replaces to the end of the current line Exit from input mode
Move the cursor l (or spacebar) h (or backspace) j (or +) k (or ) $ ^ e b #G Move the screen CTRL-D CTRL-F CTRL-B CTRL-L Search (and replace) / ? n :%s/pattern1/pattern2/g Misc (#)yy p P u . File Commands ZZ :w :w! :q! :r filename
Move to the right Move to the left Move down a line Move up a line Move to the end of the line Move to the start of a line Move to the end of a word Move to the beginning of a word Move to line number #
Scroll forward half a screen Scroll forward a full screen Scroll backwards a full screen Redraw screen
Search forward Search backwards Next occurrence Search for and replace all patern1 with pattern2
Yank a (#) line(s) Paste it below current line Paste it above Undo last command Repeat last action
Write file and quit Write file and dont quit Write file and dont complain (or quit) Quit, dont save and dont complain Read in filename after the cursor