Cisco − Using Vi to Work With the Cisco PGW...

advertisement
Cisco − Using Vi to Work With the Cisco PGW 2200 PSTN Gate
Cisco − Using Vi to Work With the Cisco PGW 2200 PSTN Gateway
Table of Contents
Using Vi to Work With the Cisco PGW 2200 PSTN Gateway.......................................................................1
Introduction.............................................................................................................................................1
Before You Begin...................................................................................................................................1
Conventions...............................................................................................................................1
Prerequisites...............................................................................................................................1
Components Used......................................................................................................................2
Vi Editor.................................................................................................................................................2
Before You Start Using Vi.........................................................................................................2
The Vi Modes............................................................................................................................2
Start and Exit Vi........................................................................................................................3
Session Customizing Commands...............................................................................................4
Cursor Motion............................................................................................................................4
Searching for Text or Characters...............................................................................................4
Regular Expressions..................................................................................................................5
Deleting and Replacing Text.....................................................................................................5
Operating System Commands................................................................................................................5
Compare−Find−Link Files.........................................................................................................6
Compress and Extract Files.......................................................................................................7
Related Information................................................................................................................................7
i
Using Vi to Work With the Cisco PGW 2200 PSTN
Gateway
Introduction
Before You Begin
Conventions
Prerequisites
Components Used
Vi Editor
Before You Start Using Vi
The Vi Modes
Start and Exit Vi
Session Customizing Commands
Cursor Motion
Searching for Text or Characters
Regular Expressions
Deleting and Replacing Text
Operating System Commands
Compare−Find−Link Files
Compress and Extract Files
Related Information
Introduction
The following document provides the reader with commands to better use the standard text editor, called the
Vi editor (pronounced "vee eye" editor), that is integrated in the Sun Microsystems Solaris Operating
Environment. This document describes how to edit the XECfgParm.dat configuration file of the Cisco Media
Gateway Controller (MGC) software application and how to use the general system commands from the Sun
Solaris Operating Environment for maintaining and viewing information. This document also covers setting
up Vi, problems with the appearance of the terminal screen, creating and modifying new and existing files, the
difference between the different Vi modes and shortcuts related to the work with these modes. The general
system commands will focus on file handling, compression, user privileges and permissions to files.
Before You Begin
Conventions
For more information on document conventions, see the Cisco Technical Tips Conventions.
Prerequisites
Readers of this document should be knowledgeable of the following:
•
Basic Solaris administration tasks and commands
•
Cisco MGC Software
Cisco − Using Vi to Work With the Cisco PGW 2200 PSTN Gateway
Components Used
The information in this document is based on the software and hardware versions below.
•
Sun Microsystems, Solaris 2.6, 2.8
•
Cisco MGC Software Release 7.4(x), 9.x.(x)
The information presented in this document was created from devices in a specific lab environment. All of the
devices used in this document started with a cleared (default) configuration. If you are working in a live
network, ensure that you understand the potential impact of any command before using it.
Vi Editor
The Vi editor is a full−screen, character−based editor for creating and modifying ASCII text files that
customize your work environment, change configuration files from applications running on the systems, and
write script files for automated tasks. This program was written in 1976 by Bill Joy and is universally
available with Unix−based systems. Vi is a powerful and flexible editor, and is organized in a logical fashion.
It is different from other editors or word processors, which makes it tricky to learn because of its many
options. Vi is case−sensitive and cannot be used along with a mouse−pointing device to position the cursor
and it does not have formatting capabilities. The Vi editor puts files in the memory buffer of the system so
they can be written to disk or be discarded directly from the buffer.
Before You Start Using Vi
If you notice a jumpy, scrolling behavior in the screen after displaying a file you opened with Vi, there is a
problem with the system's terminfo or termcap information for your terminal. If the selected terminfo/termcap
entry does not have the correct scrolling capabilities, these behaviors can come up. In such a case, you must
specify the Vi editor a different terminal to use.
In order to set the terminal correctly, you must know which shell is being used. You can see which shell is
being used by issuing the echo $shell command. In this example, the terminal is vt100. You can determine
which terminal is supported by checking the /etc/termcap file in the file system of your workstation. Reset
your terminal with the tset command and you will be ready to use Vi properly.
Shell
C Shell (/bin/csh)
Bourne Shell (/bin/sh) or Korne Shell (/bin/ksh)
Command
Set term = vt100
Export TERM
TERM = vt100
The Vi Modes
All commands available with Vi can be classified in one of the three modes: Command, Entry, and Last−line
mode. The Command mode is the default mode when starting Vi for creating and editing files, cursor
positioning, and modification of existing ASCII files. All commands are initiated from this mode. Pressing the
ESC key returns you to the Command mode.
Cisco − Using Vi to Work With the Cisco PGW 2200 PSTN Gateway
The Entry (or input) mode is used for entering new text. By using an Insert or Append command, shown in the
table below, you are taken from Command mode to Entry mode. The Entry commands are entered by
themselves without pressing the ENTER key. If you use the "vedit filename"or the ":set showmode"
parameter after starting Vi, you will see the type of Entry mode (Insert or Append) you are in, located in the
lower−right corner. If you do not see a mode displayed after doing this, it means that you are not in Entry
mode. If you want to change from Insert to Append mode, go back into the Command mode and into the
appropriate Entry mode.
The following table demonstrates different Insert and Append commands used in the Entry mode.
Description
Shortcut
Insert before cursor or before line
i, I
Append after cursor or after line
a, A
Replace one character or many characters
r, R
Open new line after or line before
o, O
The Last−line mode is used for saving your work and quitting Vi. Type a colon to get to this mode. Pressing
the ENTER key returns you to Command mode.
The following table shows you a comprehensive collection for moving between Vi modes.
From Mode
Command
Entry
Command
Last−line
Entry
Last−line
To Mode
Command/Key
Entry
Insert or Append command
Command
Escape
Last Line
Colon
Command
Enter
Last Line
Escape + Colon
Entry
Escape + Insert or Append command
Start and Exit Vi
To start the Vi editor, issue the vi or vi filename command. With the first method, you will have to specify a
filename to save your work. With the second method, you can open and modify existing files.
Save your work periodically by using the :w command (write command), or by specifying a filename behind
this command.
Exit the Vi editor by entering "ZZ" and ENTER, which is equivalent to issuing the :wq! command. The "!"
will override read−only permissions if you are the owner of the file (see the Permissions section). This will
exit Vi and save your changes from the buffer to the file on disk. To abandon the program without saving, go
into Command mode and issue the :q! command without saving. If you want to discard all of your changes
from the beginning of the last write and reedit the file, issue the :e! command from Last−line mode. If the Vi
editor crashes, you can recover the last session by issuing the vi r filename command.
The Vi help pages in Unix (man vi) do not contain descriptions of the commands. This is because the Vi
editor is part of the ex family of editors. Vi is screen−oriented and the ex editor, with its own set of
Cisco − Using Vi to Work With the Cisco PGW 2200 PSTN Gateway
commands, is line−oriented and can be used while in Vi. All the Last−line commands discussed in this
document are actually ex editor commands and you must use the ex pages in Unix (man ex) to find the
Last−line commands mentioned above.
Session Customizing Commands
The Vi editor includes options for customizing your edit sessions. These are found in the table below and are
ex editor set commands used from Last−line mode to control the function below. To have Vi options
automatically enabled when you enter Vi, create a file in the home directory. This file must be called .exrc (ex
editor run control). The set options are placed in this file without the colon in front of them (one command per
line). This file will be read every time you start a new Vi session.
Function
Command
Show line number
:set nu
Hide line number
:set nonu
Display current mode of operation (turned on
automatically if vedit is used)
:set showmode
Turn off mode display
:set noshowmode
Display all variables
:set
Display all possible Vi variable and their current setting
:set all
Cursor Motion
The cursor positioning commands are used in the Command mode when there is existing text and you want to
move around in this text. On most workstations, the cursor control keys can be used, but if this is not possible,
you can find additional commands in the table below for moving the cursor. Again, the Vi is case−sensitive,
so ensure you use the right shortcut.
Description
Left, down, up, right
Next word, blank delimited word
Beginning of word, of blank delimited word
End of word, of blank delimited word
Beginning, end of line
Moving a screen at a time forward, backward
Moving a half screen at a time forward, backward
Beginning of next line
Moving one character right (forward)
Shortcut
h, j, k, l, cursor keys
w, W
b, B
e, E
0, $
[Ctrl] f, [Ctrl] b
[Ctrl] d, [Ctrl] u
Return
Space
Searching for Text or Characters
The commands below allow for advanced editing such as finding a line or conducting search−and−replace
functions. The / and ? are Last−line commands, but they do not require a colon first.
Cisco − Using Vi to Work With the Cisco PGW 2200 PSTN Gateway
Description
Shortcut
Search forward
/string
Search backward
?string
Repeat search in same/ reverse direction
n, N
Goes to last line of file
G
Goes to line x
:x
Regular Expressions
The regular expressions in the table below, are used to define a range of parameters and variables that can be
used to have more granularity by using then together with specific functions (such as, search and replace).
Description
Any single character except newline
Zero or more repeats
Shortcut
. (dot)
*
Any character in set, not in set
Beginning, end of line
[&], [^&]
^, $
Beginning , end of word
\<, \>
Deleting and Replacing Text
The commands in this section are used in the Command mode. While in the Command mode, position the
cursor where you want it to be, and use the commands in the table below to delete or replace the text. These
commands are case−sensitive and entered without the ENTER key.
Description
To end of line
Line
Character to right, left
Replace current character
Change contents of current line
Change contents of current word (type new word and press
ESC)
Cut and Paste
Copy and Paste
Undoes all changes that you have made to the current line
Shortcut
d
dd
x, X
r
cc
cw
DD then p
yy then p
U
Operating System Commands
The following sections of this document will show commands that are useful for changing the permission of
files, compressing them for transportation, and comparing files to see differences in the content of them.
Cisco − Using Vi to Work With the Cisco PGW 2200 PSTN Gateway
Files and directories in your file system will have certain access levels for the owner, group, and others that
are using them. You can define a very high granularity for accessing them in a Unix environment. Shown
below is an example output when issuing the ls −1 command at the prompt.
#ls −1
drwxr−xr−x 2 root sys 512 Aug 6 09:30 mnt
The characters from left to right (drwxr−xr−x) of the output can be read with the table below.
Set
First Character
Second, third, and
fourth characters
Meaning
Determines if the item is a directory (d), a file
(−), or a link (l).
This set shows the permissions that have been set
for the item's "owner."
Fifth, sixth, and seventh
characters
This set shows the permissions that have been set
for the "group."
Eight, ninth, and tenth
characters
This set shows the permissions that have been set
for "other."
The table below shows the permissions that can be granted or removed from the files or directories. The
symbols in the table below are used in the syntax command of the chmod ugo+/−rwx filename command for
changing permissions.
Symbol
u
Meaning
user
g
group
o
other
other
All
r
Read
w
Write
x
Execute
+
Add permission
−
Take away permission
Compare−Find−Link Files
By issuing the following commands, you will be able to locate differences in files, find a specific file in a
directory, and use a virtual link in the directory structure.
•
diff filename1 filename2 − Displays differences in both files.
•
find directory name filename print − Looks for a specific file in a specific directory.
•
Cisco − Using Vi to Work With the Cisco PGW 2200 PSTN Gateway
ln −s folks /auto/People/ − For easier navigation through the file system and directory structure, use a
virtual link from anywhere in the directory structure. To use this link, type "cd folks."
Compress and Extract Files
Files can be compressed for backup and transport to different location. To do this on a system where the MGC
software is installed, use one of the programs from the table below. You will need to know the differences in
functionality between these programs before using them.
Program
Tar
Gzip
Uuencode
Compress
Extract
tar −cvf newfile.tar directory/
tar xvf filename.tar
Gzip filename
gunzip filename
uuencode filename > filename.uu
uuencode filename.uu
Related Information
• Cisco Media Gateway Controllers
• Sun Product Documentation
• Voice, Telephony and Messaging Technologies
• Voice, Telephony and Messaging Devices
• Voice, Telephony and Messaging Software
• Voice, Telephony and Messaging TAC eLearning Solutions
• Technical Support − Cisco Systems
All contents are Copyright © 1992−2002 Cisco Systems, Inc. All rights reserved. Important Notices and Privacy Statement.
Updated: Jan 03, 2003
Cisco − Using Vi to Work With the Cisco PGW 2200 PSTN Gateway
Document ID: 27718
Download