Unix Fundamentals
Unix Fundamentals
www.infosysinbanking.c
om
Document number: VersionRev: 1.00
Authorized by: R N NAGARAJ Signature/Date:
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
9. THE VI EDITOR...............................................................................................................................28
10. FLASHBACK..................................................................................................................................39
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.
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
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, 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.
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
CPU Scheduling
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
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
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.
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:
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.
Regular files
Directories
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.
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.
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.
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
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.1. LOGGING IN
The user needs to have a user name for logging into the Unix operating system
and using it.
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
a /etc/passwd file
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.
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.
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
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.
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
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.
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
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.
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
$ 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
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’.
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.
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.
$ 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
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
Example:
pipe “|”
Description : Channels the output of command1 as input for command2.
Example:
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
who
Description : This command lists all the users who are currently logged in,
along with the time of login and the terminal details.
Example:
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
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
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
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
NAME
finger - display information about local and remote users
SYNOPSIS
finger [ -bfhilmpqsw ] [ username... ]
finger [-l ]
[ username@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.
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
Example:
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:
chmod
Description : This command changes the access permissions of a file or
directory.
Example:
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.
talk your_address
find
Description : The find command is used to find files matching a certain set of
selection criteria.
$ find . –name file1 –print
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
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
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
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 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,
CAUTIONS ABOUT VI
The same keystrokes can have more than on meaning depending on current
mode and the key combinations are in no way mnemonic.
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.
vi is fast.
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.
Command mode
Insert mode
When in this mode, the keys are echoed in the edit buffer.
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.
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
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>.
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.
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
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
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.
Move to line 6 :6
Symbol Means
“.” Current line
where cursor is
“+” Line after current
line
“-” Line before
current line
, denotes range
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)
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
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!
“#p or “#P - # is 1 to 9
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”
All line, word and character commands can be used while yanking
d’k - deletes block from mark “k” upto current cursor position
PATTERN SEARCHING
SUBSTITUTION
:1,9s/string/string1/g
:1,$s/string/string1/g
MACROS
In insert mode press “u” “o” and press “Spc bar” or “Enter” - the macro string is
inserted at current cursor position.
The cursor movement keys j,k,l,h may be mapped by default to their respective
cursor movement keys.
:map ^X :wq^M
:unmap ^X
$ vi f*
:args
:args
:rew
:args
:e file - edits file outside chosen list but :args will not show this file in list
:1,5 w! file2
:1,5 r file2
$ vi .exrc
set nu
set showmode
:wq
Some basic UNIX commands were also discussed apart from the vi Editor.
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
QUIZ
Page 1
Infosys BBU – UET Finacle Training
Document
EXERCISES
Sl.No QUESTION
What is meant by multitasking?
1.
2. What is the output of the command “ls”?
10. What is the prompt you get when you login as super user (root)?
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?
EXERCISES
Page 1