UNIXLINUX COMMANDS VISUAL EDITOR Creating Editing files using

  • Slides: 5
Download presentation
UNIX/LINUX COMMANDS VISUAL EDITOR Creating & Editing files using vi $vi filename ` Starts

UNIX/LINUX COMMANDS VISUAL EDITOR Creating & Editing files using vi $vi filename ` Starts at line 1 $vi +n filename Starts at line n $vi + filename Starts at last line $vi +/pattern filename Starts at ’pattern’ $vi –r filename Ġ! Recovers file after a system crash Cursor Movement h -- Moves the cursor to the left (Moves one space left) j -- Moves the cursor to the next line, same column ( Moves one line down) k -- Moves the cursor to the preceeding line, same column ( Moves one line up) l -- Moves the cursor to the right ( Moves one space right) <space> -- Moves the cursor to the right ( Moves one space right) w -- Moves the cursor a word forward (Moves 1 word right) b -- Moves the cursor a word backward (Moves 1 word left) $ -- Moves the cursor to the last character of a line 0 -- Moves the cursor to the first character of a line <enter> -- Moves the cursor to the next line ( -- Moves to the beginning of the sentence ) -- Moves to the end of the sentence { -- Moves to the beginning of paragraph } -- Moves to the end of paragraph <control>u -- scrolls up ½ screen <control>d -- scrolls down ½ screen <control>b -- scrolls up one screen <control>f -- scrolls down one screen

x nx X dd ndd D dw d. O d$ 3 dw 5 dd

x nx X dd ndd D dw d. O d$ 3 dw 5 dd DELETE --delete character --delete n charaters --delete character before cursor i --delete line --delete n lines --delete rest of line -- deletes a word -- deletes to beginning of a line -- deletes to end of a line -- deletes 3 words -- deletes 5 lines INPUT a --append after cursor A --append at end of line --insert before cursor I --insert before first non-blank o --open and insert at line below O --open and insert at line above

MODIFYING EXIT AND SAVE FILES r --replaces the current character ZZ -- Exit (save

MODIFYING EXIT AND SAVE FILES r --replaces the current character ZZ -- Exit (save & quit) R --replaces until Esc : q! -- quit vi without saving changes s --substitute text for character : wq -- write(save) & quit until Esc. w - writes (save)out the file without quitting vi cw -- Changes 1 word : x -- writes the file, quits vi 3 cw -Changes 3 words c -- Changes current line 5 cc -- Changes 5 lines BLOCKING COMMANDS : nd -- Deletes nth line : m, n d -- Deletes lines from m to n : n mo p -- Move line n after line p : m, n mo p -- Move lines m to n after line p : m co p -- Copies line m after line p : m, n co p -- Copies lines m to n after line p : m, n w filename -- Writes lines m to n to a file : m, n w >> filename -- Appends lines m to n to a file : r filename -- Reads the contents of the filename at the current cursor position

TO COMPILE A PROGRAM FILE TO EXECUTE A FILE $cc filename. c -lm (

TO COMPILE A PROGRAM FILE TO EXECUTE A FILE $cc filename. c -lm ( Executable file is stored as a. out) $a. out ( Execute a file) TO COMPILE & OBJECT FILE STORED INTO SPECIFIED FILE $cc -o filename. out filename. c –lm ex: $cc -o anil. out anil. c –lm TO EXECUTE A FILE $filename. out ex: $anil. out SPECIAL COMMANDS > -- Redirecting the output to a file < -- Redirecting the input to a file Ex : anil. out<data 1>output 1 Name of the input file is data 1 and name of the output file is ouput 1 anil. out<anilin 1> anilout 1 >> -- Appending a (ouput) file. Ex: $ file 1>>file 2 file 1 is appended to file 2 u -undoes the last command U -restores the current line to its state before you changed it J -- joins the line immediately below the current line with the current line : n -- cursor move to 'n'th line yy -- Marks the current line p -- Puts the marked text in new position

$ ls Lifts the files/directories $ ls | pg Lifts the files/directories page by

$ ls Lifts the files/directories $ ls | pg Lifts the files/directories page by page $ pwd Print working directory (Present working directory) $ mkdir To create a new directory $ rmdir Removes directory $ cd To change directory $ ls-cf List files and directories columnwise $ cp anil. c pavan. c Duplication of file with another name $ cp anil. c/temp/anil. c Copies anil. c from current directory to temp directory $ mv file 1 file 2 Name of file 1 is changed to file 2 $ rm file 1 file 2 file 3 … Removes the files file 1, file 2, file 3 …. . Press “Delete” key to stop running a program