Vous êtes sur la page 1sur 47

ADMINISTRATOR TRAINING MANUAL

UNIX & vi EDITOR

www.infosysinbanking.c
om
Document number: VersionRev: 1.00
Authorized by: R N NAGARAJ Signature/Date:

Document revision list

Ver.Rev Date Author Description


1.00 13-08- Prakash Manley Original version
2003

© 2004 Infosys Technologies Limited, Bangalore, India

All rights reserved by Infosys Technologies Limited,


Electronics City,
Hosur Road,
Bangalore – 560100
India.

No part of this volume may be reproduced or transmitted in any form or by any


means electronic or mechanical including photocopying and recording or by any
information storage or retrieval system except as may be expressly permitted.

This Training manual has been written and produced by the BBU - USER EDUCATION
TEAM of Infosys Technologies Limited.

_______________________________________________________________________________________________
_
Infosys believes that the information in this publication is accurate as
of its publication date. This document could include typographical
errors, omissions or technical inaccuracies. Infosys reserves the right
to revise the document and to make changes without notice. Infosys
acknowledges the proprietary rights in the trademarks and product names
of other companies mentioned in this document.
Infosys BBU – UET Finacle Training
Document

TABLE OF CONTENTS

1. SNAPSHOT..........................................................................................................................................1

2. SECTION OBJECTIVE.....................................................................................................................1

3. OPERATING SYSTEMS – AN INTRODUCTION........................................................................1


3.1 WHAT IS AN OPERATING SYSTEM?............................................................................1
4. THE UNIX OPERATING SYSTEM ................................................................................................2

5. THE STRUCTURE OF UNIX...........................................................................................................2


5.1. THE KERNEL........................................................................................................2
5.2. SWAPPING............................................................................................................3
5.3. THE SHELL..........................................................................................................4
5.4. THE FILE SYSTEM.................................................................................................6
6. THE UNIX FILE TREE.....................................................................................................................7

7. WORKING WITH UNIX...................................................................................................................8


7.1. LOGGING IN.........................................................................................................8
7.2. DIFFERENT PRIVILEGES FOR DIFFERENT USERS ........................................................11
7.3. USING COMMANDS .............................................................................................12
8. SOME IMPORTANT UNIX COMMANDS...................................................................................16

9. THE VI EDITOR...............................................................................................................................28

10. FLASHBACK..................................................................................................................................39

UNIX Fundamentals Ver. 1.00 -i-


Infosys BBU – UET Finacle Training
Document

UNIX Fundamentals Ver. 1.00 - ii -


Infosys BBU – UET Finacle Training
Document

1. SNAPSHOT
FINACLE application works on UNIX platforms and hence some knowledge of
UNIX is essential for the administration and maintenance of the application and
the database.

This document discusses the fundamentals of the UNIX Operating System.

2. SECTION OBJECTIVE
The objective is to teach the user basic UNIX commands and make him aware of
the structure of the UNIX operating system. This awareness of the commands and
structure of UNIX would help the user a great deal in carrying out functions as the
Database Administrator.

3. OPERATING SYSTEMS – AN
INTRODUCTION

3.1 WHAT IS AN OPERATING SYSTEM?


An operating system is an integral part of a computer system. The computer
system can be viewed as being built from three general components: the
hardware, the operating system, and the applications. The hardware includes
pieces such as a central processing unit called a CPU, a keyboard, a hard drive,
and a printer.

Applications are why we use computers; they use the rest of the system to
perform the desired task. The operating system is the component that, on one
side, manages and controls the hardware and on the other, manages the
applications. When a computer system is purchased, it must have at least
hardware and an operating system. The hardware is able to use one or more
different operating systems. The operating system is necessary in order to
manage the hardware and the applications.

UNIX Fundamentals Ver. 1.00 Page 1


Infosys BBU – UET Finacle Training
Document
4. THE UNIX OPERATING SYSTEM
Having looked at an operating system in general, the UNIX operating system in
particular, will be discussed.

UNIX, like other operating systems, is a layer between the hardware and the
applications that run on the computer. It has functions that manage the hardware
and functions that manage executing applications.

5. THE STRUCTURE OF UNIX


The UNIX Operating System can be divided into three parts structurally, namely,

 A core unit called the kernel that interacts with the hardware for low level
functions

 An outer unit called the shell that interacts with the user to perform functions
desired by the user

 The File System


The idea of such a structure was to keep the units related but still separate so
that the entire program did not park itself in the memory and slow down the
system.

5.1. THE KERNEL


The core unit that manages the hardware and the executing processes is called
the kernel. When the computer is switched on, the program UNIX is loaded into
the computer's main memory, where it remains until the computer is shut down.
This program, called the kernel, performs many low-level and system-level
functions. The kernel is responsible for interpreting and sending basic instructions
to the computer's processor. The kernel is also responsible for running and
scheduling processes and for carrying out all input and output. The kernel is the
heart of a UNIX system and there is one and only one kernel.

To list, the tasks of the kernel include

 CPU Scheduling

 Allocating the necessary hardware

UNIX Fundamentals Ver. 1.00 Page 2


Infosys BBU – UET Finacle Training
Document
 Controlling the I/O operations
UNIX is a multi-tasking, multi-user operating system, which implies that several
users can work on the system at the same time and each user can submit several
jobs for execution at the same time. In order to effectively manage the several
tasks that run simultaneously, the kernel has to allot a tag that would enable the
identification of any task, uniquely. The simplest form of identification for the
kernel is the use of an integer.

For every job that is initiated, the kernel assigns an identification number called
the process id. The kernel maintains a table called the Process Tab that
describes every running process, enabling the identification of the details of the
running process by means of the process id of the process, which is also stored in
the table along with several other details. When a process is initiated, the kernel
creates an entry in the process table and this entry is discarded from the table
once the process is completed or its execution ceases. Each entry in the process
table also indicates the priority of the process. This priority is a factor that
determines the fashion or order in which the CPU allots time to the processes.
Once a process gains the attention of the CPU, the process runs for an interval
and then the CPU moves on to execute another process that deserves allocation.
The interval is the period of time for which the process runs. This concept of
giving each process a particular interval of time ensures that all processes get a
chance to run and no process starves without the allocation of the CPU. The
operating system handles the allocation and reallocation at a mind boggling speed
that the users can hardly make out that the CPU is not allotted to them and they
only have the feeling that the system is responding to all their requests
simultaneously.

5.2. SWAPPING
The memory space is as valuable a resource as the CPU time is. Needless to say,
a valuable resource as always has too many users and too little of it is available.
The program that is processed and the data of the program use the memory
space. With a number of users working on the system, at any point of time, the
memory space available is less than what is required. If a process has to be
executed, all parts of the process have to be in memory. If a process is running,
the other processes need not be present in the memory. Hence, the kernel moves
these processes that are waiting, to the secondary storage, thereby ensuring that
the running process has the memory it requires. This method adopted by the

UNIX Fundamentals Ver. 1.00 Page 3


Infosys BBU – UET Finacle Training
Document
kernel is called swapping and this happens at too high a speed for the user to be
aware of its occurrence.

5.3. THE SHELL


As the shell of a nut provides a protective covering for the kernel inside, a UNIX
shell provides a protective outer covering. As you might suspect from the critical
nature of the kernel's responsibilities, the instructions to the kernel are complex
and highly technical. To protect the user from the complexity of the kernel, and to
protect the kernel from the shortcomings of the user, a protective shell is built
around the kernel. The user makes requests to a shell, which interprets them and
passes them on to the kernel.

Once the kernel is loaded to memory, it is ready to carry out user requests. First,
though, a user must log in and make a request. For a user to log in, the kernel
must know who the user is and how to communicate with him. To do this, the
kernel invokes two special programs, getty and login. For every user port—usually
referred to as a tty—the kernel invokes the getty program. This process is called
spawning.

When getty receives any input, it calls the login program. The login program
establishes the identity of the user and validates his right to log in. The login
program checks the password file. If the user fails to enter a valid password, the
port is returned to the control of a getty. If the user enters a valid password, login
passes control by invoking the program name found in the user's entry in the
password file. This program might be a word processor or a spreadsheet, but it
usually is a more generic program called a shell.

For instance if four users have logged in, two can use the Bourne shell, one, the
Korn shell and one can be logged into a spreadsheet. Each user has a copy of the
shell to service his requests, but there is only one kernel. Using a shell does not
prevent a user from using a spreadsheet or another program, but those programs
run under the active shell. A shell is a program dedicated to a single user, and it
provides an interface between the user and the UNIX kernel.

Because any program can be executed from the login—and a shell is simply a
program—it is possible for you to write your own shell. In fact, three shells,
developed independently, have become a standard part of UNIX. They are

 The Bourne shell developed by Stephen Bourne

UNIX Fundamentals Ver. 1.00 Page 4


Infosys BBU – UET Finacle Training
Document
 The Korn shell developed by David Korn

 The C shell developed by Bill Joy


This variety of shells enables you to select the interface that best suits your needs
or the one with which you are most familiar.

BOURNE SHELL

It is the most widely used UNIX shell and is evidently, named after its developer
Stephen Bourne. The Bourne shell prompts the user with a $ symbol. The Bourne
shell, by itself, is a program by name sh.

KORN SHELL

The Korn shell has more features than the Bourne shell and is named after its
developer David Korn. It is also called ksh.

C SHELL

The C shell has still additional features and was developed by Bill Joy. It is also
called csh.

5.3.1. THE FUNCTIONS OF A SHELL

It doesn't matter which of the standard shells are chosen, for all three have the
same purpose: to provide a user interface to UNIX. To provide this interface, all
three offer the same basic functions:

 Command line interpretation

 Program initiation

 Input-output redirection

 Pipeline connection

 Substitution of filenames

 Maintenance of variables

 Environment control

 Shell programming
Discussing the functions of the shell in detail is beyond the scope of this material.

UNIX Fundamentals Ver. 1.00 Page 5


Infosys BBU – UET Finacle Training
Document
5.4. THE FILE SYSTEM
One of UNIX's greatest strengths is the consistent way in which it treats files.
Although some operating systems use different types of files each requiring
unique handling, you can handle most UNIX files the same. For instance, the cat
command, which displays a disk file on your terminal screen, can also send the
file to the printer. That is, in UNIX, all devices are addressed as files. As far as
UNIX is concerned, the printer and your terminal look the same, and they look like
any other UNIX file. UNIX also doesn't distinguish between files that you create
and the standard files that come with the operating system—as far as UNIX is
concerned, a file is a file is a file. This consistency makes it easy to work with files
because you don't have to learn special commands for every new task. Often, the
same command can be used for several purposes. This makes it easy to write
UNIX programs because the user usually doesn't have to worry whether he’s
communicating to a terminal, a printer, or an ordinary file on a disk drive.
Besides, this ensures the effective control of the access to any device, which
according to UNIX, is just another file.

5.4.1. THE TYPES OF UNIX FILES

There are four types of UNIX files namely,

 Regular files

 Directories

 Special or Device files

 FIFO files

REGULAR FILES

Regular files hold executable programs and data. Executable programs are the
commands (such as cat) that you enter. Data is information that you store for
later use. Such information can be virtually anything and there is no specific order
of format enforced in the way the information is stored.

These files can be visualised as the leaves in the UNIX tree.

UNIX Fundamentals Ver. 1.00 Page 6


Infosys BBU – UET Finacle Training
Document
DIRECTORIES

Directories are files that contain other files and subdirectories, just as a filing
cabinet's drawers hold related folders. Directories help you organise your
information by keeping closely related files in the same place so you can find
them later. For instance, the user might save all spreadsheets in a single
directory instead of mixing them with other unrelated files.

The kernel alone can write the directory file. When a file is added to or deleted
from this directory, the kernel makes an entry.

A directory file can be thought of as the branch of the UNIX tree.

SPECIAL OR DEVICE FILES

These files represent the physical devices. Files can also refer to computer
hardware such as terminals and printers. These device files can also refer to tape
and disk drives, CD-ROM players, modems, network interfaces, scanners, and any
other piece of computer hardware. When a process writes to a special file, the
data is sent to the physical device associated with it. Special files are not literally
files, but are pointers that point to the device drivers located in the kernel. The
protection applicable to files is also applicable to physical devices.

FIFO FILES

FIFO files are those that let unrelated files communicate with each other. These
files are typically used in applications where the communication path is only in
one way and where a number of processes have to communicate with a single
process, often called the daemon process. Each message writes a message to
the FIFO file and the UNIX system ensures that the other users do not overwrite a
message written in the file.

6. THE UNIX FILE TREE


The designers of UNIX used directories to organise the UNIX file system
into a structure that is shaped like an upside-down tree. Directories enable the
user to keep related files in one place, where they can be seen only when wanted.

The figure that follows shows a part of the file tree for a typical UNIX system. In
this drawing, which looks somewhat like an upside-down tree, names like home
and jane are followed by a slash (/), which indicates that they are directories, or

UNIX Fundamentals Ver. 1.00 Page 7


Infosys BBU – UET Finacle Training
Document
files of files. Note that ordinary files, such as cowboys and prufrock, are not
followed by a slash. Such files are called leaves because they aren't connected to
anything else. The connecting lines are the paths through the UNIX file tree. You
can move around the tree by following the paths.

The file tree for a typical UNIX system

Unlike some operating systems, UNIX offers great flexibility in naming files and
directories. The slash character cannot be used because it is the pathname
separator and the name of the file tree's root directory. However, almost
everything else is legal. Filenames can contain alphabetic (both upper- and
lowercase), numeric, and punctuation characters, control characters, shell wild-
card characters (such as *), and even spaces, tabs, and new lines.

7. WORKING WITH UNIX


This section discusses the process of logging into the UNIX operating system and
the prerequisites for the same.

7.1. LOGGING IN
The user needs to have a user name for logging into the Unix operating system
and using it.

UNIX Fundamentals Ver. 1.00 Page 8


Infosys BBU – UET Finacle Training
Document
USER ACCOUNT SETUP

After a UNIX system is booted, the user cannot simply start using it like any PC.
Before the user can access the computer system, someone—usually the system
administrator—must configure the computer for use.

The user must know two things before he can start using the system: his user
name and password. The user name is a unique name that identifies the user to
the system. The system administrator, before creating a user name, will verify
that no one else on the system has the same name before allowing the new user
to have it. The password that has been assigned to the user is a temporary string
that allows him to initially access the computer system. The initial password isn't
of any real importance because the user should change it to something of his
choice the first time he logs in to the system.

Whenever a new user is created by the system administrator or the super user,
the following details have to be entered in the /etc/passwd file:

 User Name

 User’s Password

 User_Id

 Group_Id

 User Description

 Home Directory

UNIX Fundamentals Ver. 1.00 Page 9


Infosys BBU – UET Finacle Training
Document

a /etc/passwd file

LOGGING IN TO THE SYSTEM

Once the system administrator has done the necessary groundwork required for a
new user, the new user can log in. The system will prompt (ask) the new user for
his user name by printing

login:

The user should then enter his user name. Next, UNIX will prompt him for his
password by printing

Password:

The user should enter his password. As the password is being typed, the user will
not be able to see the characters he typed, for obvious security reasons so that
no one else can get to know his password by looking at the screen when the user
logs in.

UNIX Fundamentals Ver. 1.00 Page 10


Infosys BBU – UET Finacle Training
Document
If the user types everything correctly and the system administrator has
everything set up correctly, the user should be able to log in and use the system.
On logging in successfully, the system puts the user on to his home directory, the
directory allotted by the super user for the user to work in. If the system displays
a message saying Login Incorrect, then the user may have typed his user name
or password incorrectly and hence the system rightfully denies access for working.

7.2. DIFFERENT PRIVILEGES FOR DIFFERENT


USERS
UNIX systems have built-in security features. Most users cannot set up a new
user account nor do other administrative procedures.

The user root is a special user, sometimes called a super-user, which can do
anything at all on the system. This high degree of power is necessary to fully
administer a UNIX system, but it also allows its user to make mistakes and cause
system problems. For this reason, the user should set up a personal account for
himself that does not have root privilege. Then, his normal, day-to-day activities
will affect only his personal environment and the user will be in no danger of
causing system-wide problems.

In a multi-user, non-personal environment, the user is most likely to have only


user, and not super-user privileges. This security is even more important when
more than one person is involved because one mistake by the root can affect
every user and the entire system.

UNIX also has security to help prevent different users from harming each other on
a multi-user system. Each user owns his or her environment and can selectively
let groups or all others have access to this work. If the user is doing private work
in one area that no one else should be allowed to see, then he should restrict
access to the owner (himself). If the user and his team members are working on
a group project, he can restrict access to the owner (himself) and everyone in his
group. If this work should be shared with many or all people on the system, then
he should allow access to everyone.

LOGGING OUT

When the user is done using the system, he should log out to prevent other
people from accidentally or intentionally getting access to his files. The normal

UNIX Fundamentals Ver. 1.00 Page 11


Infosys BBU – UET Finacle Training
Document
way to log out from almost any shell is to type exit. This causes the shell to exit,
or stop running. When the user exits from his login shell, he logs out. Some
shells, depending on the configuration, will also log the user out when he types
the end-of-file character, typically Control + D.

7.3. USING COMMANDS


Logging in UNIX performs several actions that prepare the user and the system
for each other. These include performing system accounting, initialising the user
environment, and starting a command interpreter commonly called a shell.
Commands are how the user tells the system to do something. The command
interpreter recognises these commands and passes the information off to where it
is needed. UNIX systems originally came with a command interpreter called the
Bourne Shell (usually referred to as sh). This shell is still available on most UNIX
computer systems. A newer shell that is common to most UNIX systems is the C
Shell (referred to as csh). Another commonly used, but not as pervasive, shell is
the Korn Shell (referred to as ksh). Among different shells, there is some variation
of the commands that are available.

WHAT IS A COMMAND?

A UNIX command is a series of characters that the user types. These characters
consist of words that are separated by whitespaces. A whitespace is the result of
typing one or more Space or Tab keys. The first word is the name of the
command. The rest of the words are called the command's arguments. The
arguments give the command information that it might need, or specify varying
behaviour of the command. To invoke a command, the user can simply type the
command name, followed by arguments (if any). To indicate to the shell that he is
done with typing and is ready for the command to be executed, he should press
Enter. For instance, the date command takes no arguments and hence, if the
user enters ‘date’ at the prompt and press Enter, he should see that the computer
has printed the current date and time. The echo command takes arguments. The
echo command writes, or echoes, these arguments out to the screen.

UNIX commands use a special type of argument called an option. An option


commonly takes the form of a dash made by using the minus sign key, followed
by one or more characters. The options provide information to the command.

UNIX Fundamentals Ver. 1.00 Page 12


Infosys BBU – UET Finacle Training
Document
REDIRECTING INPUT AND OUTPUT

One very pervasive concept in UNIX is the redirection of commands' input and
output. Before looking at redirection though, it is a good idea to look at input and
output without modification. UNIX uses the word standard in this subject to mean
the default or normal mode. Thus, UNIX has the term standard input, which
means input coming from the default setting, and the term standard output,
which means output going to the normal place. When the user first logs in to the
system, and the shell executes, the standard input is set to be what is typed at
the keyboard, and the standard output is set to be the display screen.

UNIX shells have special characters that signify redirection. Output redirection is
signified by the > character and input redirection is signified by the < character.
Output is commonly redirected to and input is redirected from a file. The syntax
for using output redirection with the cat command is

cat > <filename>

where <filename> is a name of the user’s choice.

Pipes are one of the ways UNIX allows users to combine several commands. The
pipe is signified by the vertical bar (|) symbol. A pipe is a means of taking the
output of one command and redirecting it as the input of another command.
Assume that the user wants to know how many files exist in his current directory.
The ls command will list all the files in the current directory and the number of
files can be counted. But UNIX has a command that counts the number of
characters, words, and lines of input and displays these statistics. Therefore,
these two commands can be combined to give the number of files in the
directory. One way of doing it would be

ls -l | wc -l.

Combining the two commands via a pipe takes the output of the first command
(the long directory listing) and gives it to the input of the second command.

MANAGING THE PASSWORD

During login, UNIX asks the user to enter his password. If he logs in for the first
time, his password is what the system administrator configured. One of the very
first things he should do after logging in is change his password so that, none,
including the system administrator, knows what it is. This can be done via the
‘passwd’ command. If the user forgets his password, even the system

UNIX Fundamentals Ver. 1.00 Page 13


Infosys BBU – UET Finacle Training
Document
administrator, cannot look it up. There is no alternative except to reset the
password to a value.

CONFIGURING YOUR ENVIRONMENT

In order to make using the shell easier and more flexible, UNIX uses the concept
of an environment. Your environment is a set of values. You can change these
values, add new values, or remove existing values. These values are called
environment variables—environment because they describe or define your
environment, and variables because they can change.

VIEWING AND SETTING ENVIRONMENT VARIABLES

Every user's environment looks a little different. Type the env command with no
arguments. The output formatting and variable names depend on which shell you
are using and how your system is configured. A typical environment might include
some of the following:

$ env
PATH=/usr/local/bin:/usr/xpg4/bin:/usr/ccs/bin:/opt/SUNWspro/bin:/usr/sbin:/bin:/u
sr/bin:/etc/b2k/install:/etc/b2k:/usr/local/lib:/oracle/ora92-64
/
bin:/unix/ibin:/FINACLE/V7/app/util::/FINACLE/V7/app/cust/INFENG/exe:/FINACLE/V7/a
pp/cust/INF
B2K_INSTALL_ID=uet7
LOGNAME=prakash1
SHELL=/bin/ksh
HOME=/users/prakash1
TERM=vt220
PWD=/users/prakash1

Some Finacle Related variables

$ echo $TBA_PROD_ROOT
/FINACLE/V7/app

$ echo $TBA_MRT
/FINACLE/V7/app/cust/INFENG/mrt

$ echo $TBA_SCRIPTS
/FINACLE/V7/app/cust/INFENG/scripts

$ echo $TBA_COPT_FILE
coptdefault.rip

$ echo $TBA_UTIL
/FINACLE/V7/app/util
Sometimes the number of variables in your environment grows quite large, so
much so that you don't want to see all of the values displayed when you are

UNIX Fundamentals Ver. 1.00 Page 14


Infosys BBU – UET Finacle Training
Document
interested in just one. If this is the case, you can use the echo command to show
an environment variable's current value. To specify that a word you type should
be treated differently—as a value of an environment variable—you immediately
precede the variable name with a dollar sign ($). Be careful not to type any
whitespace between the $ and the word. One of the variables in the example is
HOME. You probably have this variable in your environment, too. Try to display its
value using echo.

You can create a new environment variable by simply giving it a value. If you give
an existing variable a value, the old value is overwritten. One difficulty in setting
environment variables is that the way you set them depends on the shell you are
using.

In order for your screen to display the output correctly, the environment variable
TERM needs to have a reasonable value. This variable name comes from the times
when terminals were used as displays (before PCs and graphics displays were
common). Different terminals supported varying output control. Therefore, UNIX
systems have various terminal types that they support. These are not standard,
so you need to find out which terminal type to use from your support personnel. If
you are using a PC to connect to a UNIX system, your PC is running a terminal
emulation tool. Most of these tools have the capability to emulate several types of
terminal. The important point here is to make sure that your emulator and your
TERM variable are the same (or compatible). You can start off by seeing what
your TERM variable is set to, by entering ‘echo $TERM’.

SHELL STARTUP FILES

Where do all these environment variables come from? Well, the system sets up
various ones for the user. And each user commonly sets up others during the
login process. Yes, you may be doing this without even knowing it. During the
startup, which happens at login, a shell is started. This shell automatically looks in
a special place or two for some startup information. One of these places is the
user’s home directory. The startup information in the user’s home directory is
found in special files. The specific shell the user is using will determine the name
of the particular file. When the shell starts up, it examines this file and performs
whatever actions are specified. One of the common actions is to give values to
environment variables. This action is called initialising or setting the values.

UNIX Fundamentals Ver. 1.00 Page 15


Infosys BBU – UET Finacle Training
Document
One environment variable that is commonly set in a user's shell start-up file is the
PATH variable (or lowercase path for C-shell users). This variable's value is a list
of places (directories) on the system where the shell should look to locate a
command. Each command the user types, is physically located in a file
somewhere on the UNIX file system. It is possible for the same command name
to be located in different places (and to have either the same or different
behaviour when executed). Say that you have a program called my_program that
is stored in your home directory, and your friend has a program called
my_program, which is in her home directory. If you type my_program at the
prompt, the shell needs to know where to look to find the storage location of
my_program. The shell looks at the value of the PATH variable and uses the list of
directories as an ordered directory search list. The first directory that has a
my_program stops the search, and the shell executes that file. Because all files
within a single directory must be unique, this gives a straightforward and
sufficient method for finding executables (commands).

8. SOME IMPORTANT UNIX COMMANDS

GENERAL COMMANDS

banner
Description : This command prints the argument supplied, in large letters so
as to appear like a banner.

Example:
$ banner hello

# # ###### # # ####
# # # # # # #
###### ##### # # # #
# # # # # # #
# # # # # # #
# # ###### ###### ###### ####

cal
Description : The command can print the calendar for any year in the range 1
to 9999. The command, when given no arguments, generally
prints the calendar for the previous, current and following
months.

UNIX Fundamentals Ver. 1.00 Page 16


Infosys BBU – UET Finacle Training
Document
Example:
$ cal
July 2003
S M Tu W Th F S
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31

$ cal 8 1947
August 1947
S M Tu W Th F S
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31

 An unusual calendar is printed for September 1752. That is the month 11 days were
skipped to make up for lack of leap year adjustments. To see this calendar, type:
$ cal 9 1752

date
Description : This command is used to display the current system date or set
the system date.

Example:

$ date
Mon Jul 28 17:08:26 IST 2003

$ date +%a
Mon

$ date +%A
Monday

$ date +%b
Jul

$ date +%B
July

date +%d
28

$ date +%D
07/28/03

try the output for other formats like x, X, c, C . An interesting option is j

UNIX Fundamentals Ver. 1.00 Page 17


Infosys BBU – UET Finacle Training
Document

echo
Description : Displays the text supplied as argument or the contents of the
variable that is supplied as argument.

Example:
$echo Welcome to world of UNIX
Welcome to world of UNIX

 what is the output of echo * ?


passwd
Description : This command is used to change the user’s password or to create
a new password. The argument is used by the super user alone.
pg
Description : This command displays the contents of the files specified, page-
wise.

Example:

UNIX Fundamentals Ver. 1.00 Page 18


Infosys BBU – UET Finacle Training
Document

pipe “|”
Description : Channels the output of command1 as input for command2.

Example:

UNIX Fundamentals Ver. 1.00 Page 19


Infosys BBU – UET Finacle Training
Document
$ls /etc | pg
acct dmi hosts magic nsswitch.dns
aliases driver_aliases inet mail nsswitch.files
apache driver_classes inetd.conf minor_perm nsswitch.ldap
auto_home dumpadm.conf init mkfs nsswitch.nis
auto_master dumpdates init.d mknod nsswitch.nisplus
autopush ff initpipe mnttab opasswd
b2k fmthard inittab motd openwin
cfgadm fn install mount opt
chroot format ioctl.syscon mountall ouser_attr
clri format.dat iplanet mvdir pam.conf
coreadm.conf fs iu.ap name_to_major passwd
cron fsck killall name_to_sysnum path_to_inst
cron.d fsdb krb5 nca path_to_inst.old
dacf.conf fstyp labelit ncheck power.conf
datemsk ftpd lib net ppp
dcopy fuser link netconfig printers.conf
default getty llc2 netmasks profile
defaultrouter group log networks project
device.tab grpck logadm.conf nfs protocols
devlink.tab gss logindevperm nfssec.conf prtconf
dfs gtk lp nodename prtvtoc
dgroup.tab halt lu nscd.conf publickey
dhcp hostname.hme0 lvm nsswitch.conf pwck

sleep
Description : This command is used to delay a process for a period of time.

Example:

$sleep 30

wc
Description : This command does a count operation on the file given as
argument based on the options given.
Example:

$ wc /etc/passwd

58 70 2275 /etc/passwd

try the options –l, -w & -c

who
Description : This command lists all the users who are currently logged in,
along with the time of login and the terminal details.

Example:

UNIX Fundamentals Ver. 1.00 Page 20


Infosys BBU – UET Finacle Training
Document
$who
ram2 pts/8 Jul 29 15:59 (blrtwr18282.ad.infosys.com)
rajesh2 pts/9 Jul 29 09:57 (blrkec19005.ad.infosys.com)
balu1 pts/13 Jul 29 08:36 (blrkec18886.ad.infosys.com)
root pts/14 Jul 29 08:37 (blrkec18886.ad.infosys.com)
finadm pts/15 Jul 29 08:40 (blrkec18886.ad.infosys.com)
fabadm pts/16 Jul 29 09:26 (blrtwr15900.ad.infosys.com)
fabadm pts/3 Jul 29 09:33 (blrtwr15900.ad.infosys.com)
anil1 pts/4 Jul 29 09:40 (blrkec06585.ad.infosys.com)
venkat1 pts/5 Jul 29 09:42 (blrkec16592a.ad.infosys.com)
balu2 pts/6 Jul 29 10:11 (blrkec18886.ad.infosys.com)
kvs1 pts/18 Jul 29 11:45 (blrkec18900.ad.infosys.com)
kvs2 pts/19 Jul 29 11:46 (blrkec18900.ad.infosys.com)
prakash1 pts/20 Jul 29 14:39 (blrkec18930.ad.infosys.com)

ls
Description : This command lists the files if the argument is a directory. If the
argument is a file, it lists the details about the file.
Example:

$ls /users

The above command does not give much information about the files
$ls –l /users
drwxrwxr-x 3 root bin 512 Dec 1 2000 openwin
drwxrwxr-x 8 root sys 512 Dec 5 2000 opt
-r-------- 1 root sys 2985 Aug 11 10:40 oshadow
-rw-r--r-- 1 root sys 1742 Dec 5 2000 pam.conf
-r--r--r-- 1 root sys 4461 Aug 8 17:46 passwd
-r--r--r-- 1 root sys 3498 Dec 12 2000 path_to_inst
-r--r--r-- 1 root sys 3498 Dec 12 2000 path_to_inst.old
-rw-r--r-- 1 root sys 190 Dec 1 2000 printers.conf
-rw-r--r-- 1 root sys 1501 May 17 11:42 profile
-rw-r--r-- 1 root other 700 Dec 14 2000 profile.preaw
The above command lists the details of the files

-rw-r--r-- Indicates the file permissions


1 Indicates the number of links
root is the user ID of the file's owner
other is the group ID of the group
700 is the size of the file in bytes
Dec 14 2000 is the time stamp—the date and time when the file was last
modified
profile.preaw is the name of the file

The first and second columns require a bit more explanation. The first column is a
ten-character field that indicates the file's mode—its type and its permissions. In
the first line of the list, the file's mode is –rw-r--r—. The first character tells the
file type, which is a hyphen (-) for regular files, and d for directories. In this
example, the first two items are directories and rest ordinary files.

The next nine characters of the entry are the file's permissions—three sets of
three characters that control which users may access a file and what they can do

UNIX Fundamentals Ver. 1.00 Page 21


Infosys BBU – UET Finacle Training
Document
with it. The first set of three characters controls what the file's owner can do; the
second set of three characters controls what others in the group can do; and the
third set of three characters controls what all other users can do. Each set of
three characters shows read (r), write (w), and execute (x) permission, in that
order. A hyphen (-) means that the permission is denied.

The second column of the long listing is the number of links to this file.

cd
Description : This command enables the user to change his current working
directory and puts him in the directory supplied as argument. If
no argument is given, it takes him to his home directory.

Example:
$ cd

$ cd /users

$ cd ../prakash1

pwd
Description : This command prints the path name of the current working
directory.

Example:
$ pwd

head
Description : This command displays the first n lines of the files specified as
arguments

Example:
$ head /etc/services
$ head -20 /etc/services

tail
Description : This command displays a part of the file, generally the last part,
beginning at a designated place.

Example:
$ tail /etc/services
$ tail -20 /etc/services

UNIX Fundamentals Ver. 1.00 Page 22


Infosys BBU – UET Finacle Training
Document
finger
Description : This command lists the users who are logged on and details
about their terminal, time of login and so on.

Example:

$ finger prakash1
Login name: prakash1
Directory: /users/prakash1 Shell: /bin/ksh
On since Jul 29 14:39:24 on pts/20 from blrkec18930.ad.infosys.com
No unread mail
No Plan.

man
Description : This command displays the reference manual pages related to
the command given as argument.

Example:

$ man vi
Reformatting page. Wait... done

User Commands finger(1)

NAME
finger - display information about local and remote users

SYNOPSIS
finger [ -bfhilmpqsw ] [ username... ]

finger [-l ]
[ username@hostname1[@hostname2...@hostnamen] ... ]

finger [-l ] [ @hostname1[@hostname2...@hostnamen] ... ]

DESCRIPTION
By default, the finger command displays in multi-column for-
mat the following information about each logged-in user:
o user name
o user's full name
o terminal name (prepended with a `*' (asterisk) if
write-permission is denied)

FILE MANAGEMENT

cat
Description : This command can concatenates files or displays their contents.

Example:
$ cat /etc/services

$ cat -n /etc/services

cmp
Description : This command is used to compare the contents of the two file
supplied as arguments.

UNIX Fundamentals Ver. 1.00 Page 23


Infosys BBU – UET Finacle Training
Document

Example:
$ cmp file1 file2

comm
Description : This command is used to select or reject lines common to two
sorted files. It produces a three columnar output where the
columns contain lines only in file1, lines only in file2 and lines in
both files respectively.

Example:
$ comm file1 file2

cp
Description : This command is used to copy files from the given source to the
specified destination.

Example:
$ cp file1 file2

mkdir
Description : This command is used to create a directory.

Example:
$ mkdir dir1

mv
Description : This command moves or renames files and directories.

Example:
$ mv file1 file2

rm
Description : This command is used to remove files or directories.

Example:
$ rm file1

rmdir
Description : This command removes the directory specified as argument
provided it is empty.

Example:
$ rmdir dir1

cut
Description : This command is used to cut out columns from a table or fields

UNIX Fundamentals Ver. 1.00 Page 24


Infosys BBU – UET Finacle Training
Document
from each line of one or more files. The fields as specified by list
can be fixed length, that is, character positions as on a punched
card (-c option), or the length can vary from line to line and be
marked with a field delimiter character like Tab (-f option). If no
files are specified, cut reads from the standard input.

Example:

$ cut -c 1-10 /etc/services

ln
Description : A link is a directory entry referring to a file; a single file (together
with its size, all its protection information, and so on) may have
several links to it. There are two kinds of link: hard links and
symbolic links. By default ln makes hard links. A hard link to a file
is indistinguishable from the original directory entry; any changes
to a file are effective independent of the name used to reference
the file. Hard links may not span file systems and may not refer
to directories. This command is used to make a link to a file or
directory. A symbolic link contains the name of the file to which it
is linked; this file does not need to exist prior to the symbolic link.

Example:
$ ln file1 file2

$ ln –s file1 file2

$ ln –n file1 file2

FILE SECURITY

chgrp
Description : This command is used to change the group id of the files
specified to the group id specified as argument.

Example:
$ chgrp file1 dba
$ chgrp – R dir1 dba
 chgrp can be restricted in Solaris platform based on the parameter set rstchown = 1
in the /etc/system file.

chown
Description : This command is used to change the owner id of the files
specified as arguments to the owner id specified.

Example:

UNIX Fundamentals Ver. 1.00 Page 25


Infosys BBU – UET Finacle Training
Document
$ chown file1 dba
$ chown – R dir1 dba

chmod
Description : This command changes the access permissions of a file or
directory.

Example:

$ chmod 755 file1


$ chmod – R 755 dir1
$ chmod u+x file1
$ chmod u+rwx file1
$ chmod o-rwx file1

MAIL RELATED COMMANDS

mail
Description : mail provides a flexible environment for sending and receiving
messages electronically. For reading messages, mail provides
commands to allow saving, deleting, and responding to
messages. For sending messages, mail allows editing, reviewing,
and other modification of the message as it is entered.
Example:
$ mail trg1

mesg
Description : This command is used to permit or deny messages sent to a
terminal.

write
Description : This command is to copy lines from your terminal to that of
another user. When first called, it sends the message:
Message from your-logname your-tty ...

talk
Description : The talk utility is a two-way, screen-oriented communication
program.

When first invoked, talk sends a message similar to:


Message from TalkDaemon@ her_machine at time ...
talk: connection requested by your_address
talk: respond with: talk your_addressto the specified
address. At this point, the recipient of the message can reply

UNIX Fundamentals Ver. 1.00 Page 26


Infosys BBU – UET Finacle Training
Document
by typing:

talk your_address

SEARCH RELATED COMMANDS

find
Description : The find command is used to find files matching a certain set of
selection criteria.
$ find . –name file1 –print

$ find . –name core –exec rm {} \;

grep
Description : This command is used to locate a particular string. Wild card
characters can also be used for string specifications.

Example:
$ grep unix *.txt

$ grep –i unix *.txt

DISK TOOLS

df
Description : The df command displays the amount of disk space occupied by
mounted or unmounted file systems, directories, or mounted
resources, the amount of used and available space, and how
much of the file system's total capacity has been used.
Example:

$ df
/ (/dev/dsk/c0t0d0s0 ): 967332 blocks 330533 files
/usr (/dev/dsk/c0t0d0s3 ): 779990 blocks 224501 files
/proc (/proc ): 0 blocks 7862 files
/dev/fd (fd ): 0 blocks 0 files
/var (/dev/dsk/c0t0d0s4 ): 1190894 blocks 366000 files
/oracle (/dev/dsk/c0t0d0s6 ): 2264162 blocks 322103 files
/opt (/dev/dsk/c0t0d0s5 ): 553948 blocks 356316 files
/users (/dev/dsk/c0t0d0s7 ): 8689026 blocks 1014784 files
/wd (/dev/dsk/c1t1d0s0 ): 391628 blocks 828668 files
/database2 (/dev/dsk/c1t1d0s1 ): 1208750 blocks 754741 files
/wd2 (/dev/dsk/c1t1d0s3 ): 2414238 blocks 397829 files
/database1 (/dev/dsk/c1t2d0s0 ): 2266602 blocks 1508165 files
/wd1 (/dev/dsk/c1t2d0s1 ): 1498746 blocks 417826 files
/tmp (swap ): 2828544 blocks 171037 files

UNIX Fundamentals Ver. 1.00 Page 27


Infosys BBU – UET Finacle Training
Document
$ df -k
Filesystem kbytes used avail capacity Mounted on
/dev/dsk/c0t0d0s0 640967 157301 425979 27% /
/dev/dsk/c0t0d0s3 1018191 628196 328904 66% /usr
/proc 0 0 0 0% /proc
fd 0 0 0 0% /dev/fd
/dev/dsk/c0t0d0s4 721335 125896 537733 19% /var
/dev/dsk/c0t0d0s6 3099287 1967206 1070096 65% /oracle
/dev/dsk/c0t0d0s5 721335 444361 219268 67% /opt
/dev/dsk/c0t0d0s7 8572345 4227844 4258778 50% /users
/dev/dsk/c1t1d0s0 8261393 8065579 113201 99% /wd
/dev/dsk/c1t1d0s1 6196234 5591859 542413 92% /database2
/dev/dsk/c1t1d0s3 2940743 1733624 1148305 61% /wd2
/dev/dsk/c1t2d0s0 12390920 11257619 1009392 92% /database1
/dev/dsk/c1t2d0s1 5022314 4272941 699150 86% /wd1
swap 1417912 3640 1414272 1% /tmp

du
Description : summarize disk usage
The du command reports the number of disk blocks used for each
directory and subdirectory, and the files found there. It has an
option to display the number of blocks of just the "top level"
directory.

Example:

$ du
2 ./tmp
22 ./web/images/_vti_cnf
174 ./web/images
244 ./web
828 ./index/temp
836 ./index
14 ./.fm/users/balu1
16 ./.fm/users
18 ./.fm
14 ./.bin
2 ./database/utidb
2 ./database/utiarch
6 ./database
974 ./sql
32738 ./gary
274 ./TMP
2 ./.wastebasket
396 ./scripts
28 ./tape
16 ./menu
132258 .

9. THE VI EDITOR
A combination of << and cat can be used to add lines to a file, and sed and file
redirection can be used to modify the contents of a file. These tools are rough and
awkward, and when it's time to either create new files or modify existing ones, a

UNIX Fundamentals Ver. 1.00 Page 28


Infosys BBU – UET Finacle Training
Document
screen-oriented editor is needed. In UNIX, the screen editor of choice is called vi.
vi is Visual Editor, in short.

There are a number of editors that may be included with the UNIX system,
including ed, ex, vi, and EMACS. The latter two use the entire screen, a big
advantage, and both are powerful editors.

The vi is a modal editor. A mode is like an environment. Different modes in vi


interpret the same key differently. For example, if the user is in insert mode,
pressing the A key adds an ‘a’ to the text, whereas in command mode, pressing
the A key enters a, a single key abbreviation for the append command. Pressing
Esc always returns the user to the command mode and if the system is already in
command mode, it beeps to remind the user of that fact.

The second important characteristic of vi is that it's a screen-oriented program. It


must know what kind of terminal, computer, or system that the user is using to
work with UNIX. This probably won't be a problem because most systems are set
up so that the default terminal type matches the terminal or communications
program that the user is using.

The vi command by itself starts the editor, ready for the user to create a new file.
The vi command with a filename starts vi with the specified file, so that the user
can modify that file immediately.

There are primarily two types of editors available under UNIX namely,

 The ed line editor comparable to EDLIN IN DOS.


 The vi editor, a full screen editor.

CAUTIONS ABOUT VI

 The vi editor is very user unfriendly and offers no help facility.

 The same keystrokes can have more than on meaning depending on current
mode and the key combinations are in no way mnemonic.

 The editor is fanatically case-sensitive

 The vi command does not lock a file while editing it. So it is possible that more
than one user can edit it at the same time. The version of the file saved last is
the one that is retained.

UNIX Fundamentals Ver. 1.00 Page 29


Infosys BBU – UET Finacle Training
Document
SALIENT FEATURES OF VI

 vi is omnipresent and is available in all UNIX systems.

 vi is fast.

 vi has got powerful UNDO features.

 vi has got a lot of support .

THE BASICS OF VI

vi and ex commands are compatible with each other but ex is a line editor only.
All editing in vi is done in a buffer on a copy of the original until it is saved.

vi works in 3 different modes :

 Command mode

When in this mode, all keys are interpreted as commands.

 Insert mode
When in this mode, the keys are echoed in the edit buffer.

 The ex Escape or The Esc colon (:) mode


When in this mode, the keys are interpreted as commands and are echoed at the
command line at the bottom of vi screen.

The bottom most line in vi is the command line where all commands in Esc : mode
and messages are displayed. There are no error massages in vi - only beeps
indicate the errors. Control or special keys cannot be used and the arrow keys
cannot be used for cursor movement on most terminals.

IMPORTANT KEYS AND COMMANDS

KEY MEANING
The Esc key Returns vi to the command mode and cancels partially formed
commands.
The Return or Executes commands entered in ex Esc mode and starts a new line in
Enter key Ins mode. In command mode, it simply takes the cursor to next line.
Forward Slash Specifies a string to be searched for in the existing file – the string
“/” appears in the status line following the forward slash “/” and is
echoed at the beginning of the command line.
Question Mark Same as the forward slash key but the search is done backwards.
“?”
Colon To enter “ex Esc” mode - the command appears at the command

UNIX Fundamentals Ver. 1.00 Page 30


Infosys BBU – UET Finacle Training
Document
“:” line preceded by “:”.
Tilde Appears at the beginning of every line in vi.
“~”

INVOKING VI

COMMAND FUNCTION
vi Starts an empty edit buffer.
vi <filename> Edits the file <filename> or creates
the file <filename> if it does not
exist.
vi +3 <filename> Opens the file <filename> and goes
to the third line.
vi + /bye Searches for the first occurrence of
<filename> “bye” in the file <filename>.

CURSOR MOVEMENTS - NAVIGATING IN A FILE

The arrow keys should not be used to move, in vi though some terms do support
them.
k or -
(Up
arrow)

h or
Bkspc vi l or spc
bar

j or + or
Enter
All vi commands involve the use of alphabetical keys, alone or in combination with
Shift and Control Keys.

MORE CURSOR CONTROL IN VI

Commands marked with # can be invoked with a number preceding them


indicating repeat count.

COMMAND FUNCTION
#w Moves forward by a word
#W Moves forward by a word till next
space
#e Goes to the last character in the

UNIX Fundamentals Ver. 1.00 Page 31


Infosys BBU – UET Finacle Training
Document
word
#E Same as #e but ignores
punctuation
f[character] Upto specified character in current
line – right
F[character] Same as above but - left
t[character] Same as f[c] but one character
before
T[character] Same as F[c] but one character
before
#b Go back by a word
#B Same as #b , but ignores
punctuation
0 or ^ Goes to the beginning of a line
#$ Goes to the end of the line
#G Go to the line number # of the file
L Go to the last line

SCREEN COMMANDS

COMMAND FUNCTION
Ctrl-F Scrolls a screen forward -
except last two lines
Ctrl-B Scrolls a screen backwards
Ctrl U Scrolls forward by half a
screen
Ctrl-D Scrolls backwards by half a
screen
Ctrl R or Ctrl L Re-draw and clear messages
Ctrl-G Status of edit

DELETING DATA

COMMAND FUNCTION
#dd Delete current line where cursor is
present
#dw Delete words from the cursor position
#dW Same as #dw but includes punctuation
#x Delete character at the cursor position
#X Delete character before the cursor
d$ or D Delete current line from the cursor
position to the end of the line
d0 Delete current line from the cursor
position up to start of line

TEXT INSERTION

COMMAND FUNCTION
I Invokes insert mode and inserts

UNIX Fundamentals Ver. 1.00 Page 32


Infosys BBU – UET Finacle Training
Document
before character
I Same as i but insertion at
beginning of line
O Opens a blank line above current
line
o Opens a blank line below the
current line
a Same as i but inserts after cursor
A Same as a but appends at end of
line

JOINING

The J command causes the lines of text below the current line to get joined with
the current line.

LINE NUMBERING

In ex Esc mode the command : set nu sets line numbers and : set nonu removes
them.

Block moves - Colon Commands

Copy 2 nd line after 5 th :2co5

Multiple lines copy :1,3co$

$ for last line, 1,3 is range

Move to line 6 :6

Delete three consecutive lines now (#dd) 3dd

Yet another way -

Symbol Means
“.” Current line
where cursor is
“+” Line after current
line
“-” Line before
current line

Delete 3 lines after current line : .+3d

Delete 3 lines below current line including current line :.,+3d

, denotes range

Move line 1 to after line 3 : 1mo3

UNIX Fundamentals Ver. 1.00 Page 33


Infosys BBU – UET Finacle Training
Document
Lines 1,2 and 3 after line 5 : 1,3mo5

SAVING AND EXITING

COMMAND FUNCTION
“:q!” Quit and abandon
changes
“:wq” Save and quit
“:x” Replace old copy with
new and quit
“ZZ” Save and Quit (from
command mode)

REPLACING EXISTING TEXT

COMMAND FUNCTION
“r” Replace a single c at current cursor position
“R” Invoke insert mode and go on replacing till Esc
“s” Replace a single c with text - insert mode - continues till Esc - $
appears after c to be replaced
“S” Replace current line with new text - blanks entire current line -
invokes insertion mode
“cw” Replaces a word - $ at end of word - replacement continues after end
of $ if word size greater than current word
“C” Same as cw but acts on rest of line from current cursor position
“cc” Same as C but entire line

CUT AND PASTE

COMMAND FUNCTION
“#yy” Yank (cut !) specified number of lines into
yank buffer
“p” Paste from yank buffer below current line
“P” Same as p but above current line

9 LIVES!

vi offers undo of as many as 9 line deletions (each deletion may be a group of


lines ) apart from the usual undo “u” . This follows the LIFO (Last In First Out)
rule –

“#p or “#P - # is 1 to 9

UNIX Fundamentals Ver. 1.00 Page 34


Infosys BBU – UET Finacle Training
Document
USER DEFINED REGISTERS

vi offers 26 registers (buffers) named “a” to “z” to the user into which text may be
yanked and put anywhere else in the file using the “put” commands. These
assignments are active during the entire current session -

a5yy - yank 5 whole lines including current and place in user defined buffer “a”

ap - put contents of “a” below current line

All line, word and character commands can be used while yanking

MARKING AND YANKING

Marking the current cursor position-

mk - “m” for mark , “k” is block name (In command mode)

‘k - flips cursor to mark “k” from anywhere else in file

d’k - deletes block from mark “k” upto current cursor position

“ay’k - yanks into register “a”

“ap - puts contents of “a”

PATTERN SEARCHING

Basic commands are :

/g search for pattern “g” forwards

?g search for pattern “g” backwards

n repeat the last / or ? command

SUBSTITUTION

These are ‘:’ (colon) commands.

To replace “string” by “string1” on the current line -

:s/string/string1/ - replaces only first occurrence

:s/string/string1/g - replaces all occurrences

Substitution can occur on multiple lines if range is specified -

:1,9s/string/string1/g

For substituting throughout the file -

:1,$s/string/string1/g

UNIX Fundamentals Ver. 1.00 Page 35


Infosys BBU – UET Finacle Training
Document
OR

:g/string/s//string1/g - note the double slash.

MACROS

vi macros are created using the “abbr” command -

:abbr uo “UNIX operating system”

In insert mode press “u” “o” and press “Spc bar” or “Enter” - the macro string is
inserted at current cursor position.

:abbr -lists the macros defined

Macros can be unabbreviated or deleted -

:una uo - deletes macro uo

MAPPING KEYS TO COMMANDS

The “map” command maps a user defined key to a specific function.

The cursor movement keys j,k,l,h may be mapped by default to their respective
cursor movement keys.

To map the key “ctrl-X” to the “wq” command –

:map ^X :wq^M

- note that ^M signifies <CR> , in Vi “^” is typed by typing “Ctrl-v”

 Note : All characters typed with “ctrl” is taken as upper-case


An “unmap” command is available to cancel assignments -

:unmap ^X

Mapping in insert mode done using the “map!” command -

:map! ^x Sam fox

- In insert mode “Ctrl-x” will insert “Sam fox in the editor

An insert mode map cannot be unmapped unlike abbr

:map displays only keys mapped to command mode functions

RUNNING SHELL COMMANDS FROM WITHIN

 “:sh” temporarily “shells out” to $ and “ctrl-d” returns the shell


 “: !<command>“ “!” stands for run which will directly run
<command>

UNIX Fundamentals Ver. 1.00 Page 36


Infosys BBU – UET Finacle Training
Document

READING COMMAND OUTPUT FROM WITHIN

This is done using “:r!” -

:r! date - reads in output of “date” at current cursor position

:r! banner Hi there

EDITING MULTIPLE FILES SIMULTANEOUSLY

vi can take multiple file arguments -

$ vi file1 file2 ..... OR metacharacters -

$ vi f*

:args

[file1] file2 file3 - The bracketed file taken for display/edit

:n - Switches to next file in list

:args

file1 [file2] file3

:rew

:args

[file1] file2 file3 -i.e. “rew” rewinds to file1

:rew! - discards changes and coercively rewinds

:e file - edits file outside chosen list but :args will not show this file in list

READ AND WRITE ACROSS FILES

Write first five lines of text from file1 to file2-

:1,5 w! file2

Read same text from file2 to file1-

:1,5 r file2

THE “SET” OPTIONS

The “set” option helps customise the vi environment -

UNIX Fundamentals Ver. 1.00 Page 37


Infosys BBU – UET Finacle Training
Document
: set all - displays all “set” options available

The more common options are:

SET COMMAND DEFAULT DESCRIPTION


:set number,nu nonumber Line numbers
:set showmode noshowmode Display vi mode
:set autowrite,aw noaw Save on n, rew, !
:set autoindent,ai noai Indent as first line
:set beautify,bf nobeautify Control characters
omitted
:set directory,dir dir-/tmp Sets temporary
directory
:set errorbells,eb noeb No error beep
:set ignorecase,ic noic Uppercase as lowercase
:set magic magic Allow all
metacharacters
:set mesg nomesg Inhibit Write messages
:set redraw noredraw Act as intelligent
terminal
:set scroll scroll=half window No. of lines to scroll
:set shell sh=/bin/sh Set which shell
:set term value of TERM Set which terminal
:set terse noterse Error messages terse
:set warn warn Warn save on Shell Esc
:set window window speed No of lines in text
dependent window
:set wrapscan,ws ws Wrap pattern on find
:set wm=0 Blank screen margin
warpmargin,wm right
:set writeany, wa nowa Allow writes freely

The “.exrc” file


vi reads .exrc before loading and all options like map,abbr and set can be entered
here so that they are permanent for that vi session -

$ vi .exrc

set nu

set showmode

abbr uo UNIX operating system

map ^k :r! date^M

:wq

UNIX Fundamentals Ver. 1.00 Page 38


Infosys BBU – UET Finacle Training
Document
10. FLASHBACK
This document discussed in brief, the fundamentals of the UNIX operating system.

Some basic UNIX commands were also discussed apart from the vi Editor.

UNIX Fundamentals Ver. 1.00 Page 39


Infosys BBU – UET Finacle Training
Document
QUIZ

TOPIC: UNIX AND vi EDITOR

Srl.No. Question True False


1. Operating system is an interface between user and computer

2. Unix is a multi-user and non multitasking operating system

3. The Operating System takes care of housekeeping activities

4. The unit which interacts with user is called KERNEL

5. Shell is a core unit in a Unix system

6. Unix treats all devices as files

7. Read the following and answer the questions a, b and c


-rw-r--r-- 1 sam1 staff 540 Aug 22 15:10 test
(a) test is a directory file

(b) sam1 is the owner of the file test

(c) owner of the file test has execute permissions


8. “ls” is a list command

9. vi is one of the editors in Unix

10. Console is a monitor connected to server

11. Whenever a new user is created in Unix his/her details are entered
in /etc/passwd file
12. System administrator can see other user’s passwords

13. One general user can change another user’s password

14. Users can change their passwords

15. All the Unix commands work on all platforms

QUIZ
Page 1
Infosys BBU – UET Finacle Training
Document

EXERCISES

TOPIC : UNIX FUNDAMENTALS

Sl.No QUESTION
What is meant by multitasking?
1.
2. What is the output of the command “ls”?

3. How to create a directory?

4. What does rm <filename> do?

5. How to remove a directory?

6. What is the command used for copying?

7. How to change ownership?

8. How to find out the users logged in?

9. Which command is used for pattern matching?

10. What is the prompt you get when you login as super user (root)?

11. How do you use the command “mount”?

12. What does the “tar” command do?

13. How do you find out the space occupied in the file systems?

14. How do you find out the space available in all file systems?

15. What are the roles of a system administrator?

EXERCISES
Page 1

Vous aimerez peut-être aussi