5
List of Commands for vi - An Unix Editor Complete documentation is available by typing: man vi at the unix prompt. Starting an Editing Session: vi filename where filename is the name of the file to be edited. Undo Command: u undo the last command. Screen Commands: CTL/l Reprints current screen. CTL/L Exposes one more line at top of screen. CTL/E Exposes one more line at bottom of screen. CTL/F Pages forward one screen. CTL/B Pages back one screen. CTL/D Pages down half screen. CTL/U Pages up half screen. Cursor Positioning Commands: j Moves cursor down one line, same column. k Moves cursor up one line, same column. h Moves cursor back one character. l Moves cursor forward one character. RET Moves cursor to beginning of next line.

CommonUnixCommands

Embed Size (px)

Citation preview

Page 1: CommonUnixCommands

8/7/2019 CommonUnixCommands

http://slidepdf.com/reader/full/commonunixcommands 1/5

List of Commands for vi - An Unix Editor

Complete documentation is available by typing:

man vi

at the unix prompt.

Starting an Editing Session:

vi filename

where filename is the name of the file to be edited.

Undo Command:

u

undo the last command.

Screen Commands:

CTL/lReprints current screen.

CTL/LExposes one more line at top of screen.

CTL/EExposes one more line at bottom of screen.

CTL/FPages forward one screen.

CTL/BPages back one screen.

CTL/DPages down half screen.

CTL/UPages up half screen.

Cursor Positioning Commands:

jMoves cursor down one line, same column.

k Moves cursor up one line, same column.

hMoves cursor back one character.

lMoves cursor forward one character.

RETMoves cursor to beginning of next line.

Page 2: CommonUnixCommands

8/7/2019 CommonUnixCommands

http://slidepdf.com/reader/full/commonunixcommands 2/5

0Moves cursor to beginning of current line.

$Moves cursor to end of current line.

SPACEMoves cursor forward one character.

nGMoves cursor to beginning of line n. Default is last line of file.

0Moves the cursor to the first character of the line.

:nMoves cursor to beginning of line n.

bMoves the cursor backward to the beginning of the previous word.

eMoves the cursor backward to the end of the previous word.

w

Moves the cursor forward to the next word.

/patternMoves cursor forward to next occurrence of pattern.

?patternMoves cursor backward to next occurrence of pattern.

nRepeats last / or ? pattern search.

Text Insertion Commands:

aAppends text after cursor. Terminated by escape key.

AAppends text at the end of the line. Terminated the escape key.

iInserts text before cursor. Terminated by the escape key.

IInserts text at the beginning of the line. Terminated by the escape key.

oOpens new line below the current line for text insertion. Terminated by the escape key.

OOpens new line above the current line for text insertion. Terminated by the escape key.

DELOverwrites last character during text insertion.

ESCStops text insertion. The escape key on the DECstations is the F11 key.

Text Deletion Commands:

x

Page 3: CommonUnixCommands

8/7/2019 CommonUnixCommands

http://slidepdf.com/reader/full/commonunixcommands 3/5

Deletes current character.dd

Deletes current line.dw

Deletes the current word.d)

Deletes the rest of the current sentence.D, d$

Deletes from cursor to end of line.P

Puts back text from the previous delete.

Changing Commands:

cwChanges characters of current word until stopped with escape key.

c$

Changes text up to the end of the line.C, cc

Changes remaining text on current line until stopped by pressing the escape key.

~Changes case of current character.

xpTransposes current and following characters.

JJoins current line with next line.

sDeletes the current character and goes into the insertion mode.

rxReplaces current character with x.

R Replaces the following characters until terminated with the escape key.

Cut and Paste Commands:

yyPuts the current line in a buffer. Does not delete the line from its current position.

pPlaces the line in the buffer after the current position of the cursor.

Appending Files into Current File:

:R filenameInserts the file filename where the cursor was before the ``:'' was typed.

Exiting vi:

Page 4: CommonUnixCommands

8/7/2019 CommonUnixCommands

http://slidepdf.com/reader/full/commonunixcommands 4/5

ZZExits vi and saves changes.:wqWrites changes to current file and quits edit session.:q!Quits edit session (no changes made).

File-Related commands:

  Manipulating Files And Directories

cat - concatenates and prints to the screen.

cat file . . .

cd - change directory.

cd

cd directoryname

chmod - change modes or permissions on files.

chmod ugo, +, rwx file . . . or directory . . .

or 

chmod ugo, - , rwx file . . . or directory . . .

Who:

u Login owner 

g Group.

o Other users.

Op-codes:

+ Add permission.

- Remove permission.

Permission:

r Read.

w Write.

x Execute.

cp - make copy of file.

cp file1 file2

cp file . . . (file, file . . . , directory)

ln - makes file links.

ln file1 file2

ln file1 file2 ... directoryname

ls - lists contents of directory.

ls [ -a,c,l,r,s + others] directory . . .

Page 5: CommonUnixCommands

8/7/2019 CommonUnixCommands

http://slidepdf.com/reader/full/commonunixcommands 5/5

Options:

-a List all entries.

-c Sort and list by time of file creation.

-l List in long format.

-p Marks directories with a /.

-r Reverses the order of the listing.

-s Gives the size in blocks.

mkdir - makes new directory.

mkdir directoryname

mv - moves or renames files.

mv filename1 filename2 or filename1 directoryname

rm - removes files.

rm [-r] file . . .

Options:

-r Deletes a directory and every file or directory in it. (Be careful!)

rmdir - removes directories.

rmdir directory . . .

• Pipes - |

Example:

cat listA listB | elm paula mails paula the two files in one message.

Information Handling:

grep - search a file for a pattern.

grep [-n, -c, -v] pattern file . . .

Options:

-i Disregards upper and lower case.

-n Precedes each matching line with its line number.

-c Prints only a count of matching lines.

-v Prints all lines that do not match.

tail - gives the last part of a file.

tail [-n] file

Options:

-n Start "n" lines from the end.

Example:

tail -20 gate prints the last 20 lines of the file gate.