Beruflich Dokumente
Kultur Dokumente
2
DBA Training Manual
www.infosysinbanking.co m
1.01
1.00 1.01
02-062001 16-082001
2001 Infosys Technologies Limited, Bangalore, India All rights reserved by Infosys Technologies Limited, Infosys Towers, No. 27, J. P. Nagar, 3rd Phase Bannerghatta Road, Bangalore 560 076 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 Document
BBU UET
Finacle Training
TABLE OF CONTENTS
1. SNAPSHOT...............................................................................................................................................1 2. SECTION OBJECTIVE.........................................................................................................................1 3. OPERATING SYSTEMS AN INTRODUCTION..........................................................................1 1.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 .........................................................................................10 7.3. USING COMMANDS .................................................................................................................................11 8. SOME IMPORTANT UNIX COMMANDS.....................................................................................15 9. THE VI EDITOR...................................................................................................................................28 10. FLASHBACK........................................................................................................................................38
UNIX Fundamentals
Ver. 1.01
-i-
Infosys Document
BBU UET
Finacle Training
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.
UNIX Fundamentals
Ver. 1.01
Page 1
Infosys Document
BBU UET
Finacle Training
4.
5.
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 Allocating the necessary hardware Controlling the I/O operations
UNIX Fundamentals
Ver. 1.01
Page 2
Infosys Document
BBU UET
Finacle Training
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 kernel is called swapping and this happens at too high a speed for the user to be aware of its occurrence.
UNIX Fundamentals
Ver. 1.01
Page 3
Infosys Document
BBU UET
Finacle Training
The Bourne shell developed by Stephen Bourne The Korn shell developed by David Korn
UNIX Fundamentals
Ver. 1.01
Page 4
Infosys
BBU UET
Finacle Training
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.
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.01
Page 5
Infosys Document
BBU UET
Finacle Training
5.4.1.
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.01
Page 6
BBU UET
Finacle Training
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.
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.
UNIX Fundamentals
Ver. 1.01
Page 7
Infosys Document
BBU UET
Finacle Training
jane are followed by a slash (/), which indicates that they are directories, or 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.
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 newlines.
7.
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.01
Page 8
Infosys Document
BBU UET
Finacle Training
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 Users Password User_Id Group_Id User Description Home Directory
UNIX Fundamentals
Ver. 1.01
Page 9
Infosys Document
a /etc/passwd file
BBU UET
Finacle Training
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. 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.
UNIX Fundamentals
Ver. 1.01
Page 10
Infosys Document
BBU UET
Finacle Training
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 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-offile character, typically Control + D.
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 whitespace. Whitespace is the result of
UNIX Fundamentals
Ver. 1.01
Page 11
Infosys Document
BBU UET
Finacle Training
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.01
Page 12
Infosys Document
BBU UET
Finacle Training
words, and lines of input and displays these statistics. Therefore, these two commands 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.
$ env
UNIX Fundamentals
Ver. 1.01
Page 13
Infosys Document
$ echo $TBA_PROD_ROOT /wd2/V6200 $ echo $TBA_MRT /wd2/V6200/cust/mrt $ echo $TBA_SCRIPTS /wd2/V6200/cust/scripts $ echo $TBA_COPT_FILE defaultcopt01.rip $ echo $B2K_SECURE_ID UET
BBU UET
Finacle Training
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 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 differentlyas a value of an environment variableyou 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). Start by seeing what your TERM variable is set to by entering echo $TERM.
UNIX Fundamentals
Ver. 1.01
Page 14
Infosys Document
BBU UET
Finacle Training
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 users home directory. The startup information in the users 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. 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 as 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.
GENERAL COMMANDS
banner Description : This command prints the argument supplied, in large letters so as to appear like a banner. Example:
UNIX Fundamentals
Ver. 1.01
Page 15
Infosys Document
$banner # # # # # # ####### # # # # # # HELLO ####### # # ##### # # ####### # # # # # # ####### # # # # # # #######
BBU UET
Finacle Training
####### # # # # # # # # # # #######
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. Example:
$cal August 2001 S M Tu W 1 5 6 7 8 12 13 14 15 19 20 21 22 26 27 28 29
Th 2 9 16 23 30
F S 3 4 10 11 17 18 24 25 31
F S 1 2 8 9 15 16 22 23 29 30
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:
UNIX Fundamentals
Ver. 1.01
Page 16
Infosys Document
$ date Thu Aug 16 17:54:32 GMT 2001 $ date +%a Thu $ date +%A Thursday $ date +%b Aug $ date +%B August date +%d 16 $ date +%D 08/16/01
BBU UET
Finacle Training
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:
UNIX Fundamentals
Ver. 1.01
Page 17
Infosys Document
BBU UET
Finacle Training
$pg /etc/passwd root:x:0:1:Super-User:/:/sbin/sh daemon:x:1:1::/: bin:x:2:2::/usr/bin: sys:x:3:3::/: adm:x:4:4:Admin:/var/adm: lp:x:71:8:Line Printer Admin:/usr/spool/lp: smtp:x:0:0:Mail Daemon User:/: uucp:x:5:5:uucp Admin:/usr/lib/uucp: nuucp:x:9:9:uucp Admin:/var/spool/uucppublic:/usr/lib/uucp/uucico listen:x:37:4:Network Admin:/usr/net/nls: nobody:x:60001:60001:Nobody:/: noaccess:x:60002:60002:No Access User:/: nobody4:x:65534:65534:SunOS 4.x Nobody:/: ora734:x:1001:101::/oracle/ora734/app/oracle/product/7.3.4:/bin/sh op:x:1002:101:Backup Operator:/users/op:/bin/sh ccd:x:0:1:ROOT eqv:/users/ccd:/bin/sh balu1:x:1003:10:Balaji Srirangarajan:/users/balu1:/bin/ksh balu2:x:1004:10:Balaji Srirangarajan:/users/balu2:/bin/ksh balu:x:0:10::/users/balu:/bin/ksh sandhya2:x:1007:10::/users/sandhya2:/bin/ksh sam1:x:1008:10::/users/sam1:/bin/ksh
wc
UNIX Fundamentals
Ver. 1.01
Page 18
Infosys Document
Description Example:
$ wc /etc/passwd 99 125 4461 /etc/passwd
BBU UET
:
Finacle Training
This command does a count operation on the file given as argument based on the options given.
who Description : This command lists all the users who are currently logged in, along with the time of login and the terminal details. Example:
$who root balu1 bancs kvs1 kvs2 kvs1 console pts/13 pts/18 pts/19 pts/21 pts/22 Jul Aug Aug Aug Aug Aug 15 16 16 16 16 16 09:30 09:43 10:05 11:17 11:18 18:35 (:0) (192.168.83.145) (192.168.83.145) (192.168.83.217) (192.168.83.217) (192.168.81.141)
ls Description Example:
$ls /users
This command lists the files if the argument is a directory. If the argument is a file, it lists the details about the file.
The above command does not give much information about the files
$ls l /users drwxrwxr-x 3 drwxrwxr-x 8 -r-------1 -rw-r--r-1 -r--r--r-1 -r--r--r-1 -r--r--r-1 -rw-r--r-1 -rw-r--r-1 -rw-r--r-1 root root root root root root root root root root bin sys sys sys sys sys sys sys sys other 512 512 2985 1742 4461 3498 3498 190 1501 700 Dec Dec Aug Dec Aug Dec Dec Dec May Dec 1 2000 openwin 5 2000 opt 11 10:40 oshadow 5 2000 pam.conf 8 17:46 passwd 12 2000 path_to_inst 12 2000 path_to_inst.old 1 2000 printers.conf 17 11:42 profile 14 2000 profile.preaw
The above command lists the details of the files -rw-r--r-1 root other 700 Dec 14 2000 profile.preaw Indicates the file permissions Indicates the number of links is the user ID of the file's owner is the group ID of the group is the size of the file in bytes is the time stampthe date and time when the file was last modified is the name of the file
UNIX Fundamentals
Ver. 1.01
Page 19
Infosys Document
BBU UET
Finacle Training
The first and second columns require a bit more explanation. The first column is a ten-character field that indicates the file's modeits 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 permissionsthree sets of three characters that control which users may access a file and what they can do 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 ../trg1
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:
UNIX Fundamentals
Ver. 1.01
Page 20
Infosys Document
$ head $ head /etc/services -20 /etc/services
BBU UET
Finacle Training
tail Description : This command displays a part of the file, generally the last part, beginning at a designated place. Example:
$ tail $ tail /etc/services -20 /etc/services
finger Description : This command lists the users who are logged on and details about their terminal, time of login and so on. Example:
$ finger balu1 Login name: balu1 In real life: Balaji Srirangarajan Directory: /users/balu1 Shell: /bin/ksh On since Aug 17 09:55:37 on pts/24 from 192.168.83.145 No unread mail No Plan.
man Description : This command displays the reference manual pages related to the command given as argument.
Example:
UNIX Fundamentals
Ver. 1.01
Page 21
Infosys Document
$ man vi Reformatting page. User Commands NAME Wait... done
BBU UET
Finacle Training
finger(1)
DESCRIPTION By default, the finger command displays in multi-column format 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 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
UNIX Fundamentals
Ver. 1.01
Page 22
Infosys Document
BBU UET
specified destination.
Finacle Training
Example:
$ cp file1 file2
mv Description Example:
$ mv file1 file2
rm Description 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 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
UNIX Fundamentals
Ver. 1.01
Page 23
Infosys Document
BBU UET
Finacle Training
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 filesystems 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:
$ 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
UNIX Fundamentals
Ver. 1.01
Page 24
BBU UET
Finacle Training
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 by typing: talk your_address the message can reply
UNIX Fundamentals
Ver. 1.01
Page 25
Infosys Document
$ find . name file1 print $ find . name core exec rm {} \;
BBU UET
Finacle Training
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 and how resources, the amount of used and available space, much of the file system's total capacity has been used. Example:
UNIX Fundamentals
Ver. 1.01
Page 26
Infosys Document
$ df / /usr /proc /dev/fd /var /oracle /opt /users /wd /database2 /wd2 /database1 /wd1 /tmp $ df -k Filesystem /dev/dsk/c0t0d0s0 /dev/dsk/c0t0d0s3 /proc fd /dev/dsk/c0t0d0s4 /dev/dsk/c0t0d0s6 /dev/dsk/c0t0d0s5 /dev/dsk/c0t0d0s7 /dev/dsk/c1t1d0s0 /dev/dsk/c1t1d0s1 /dev/dsk/c1t1d0s3 /dev/dsk/c1t2d0s0 /dev/dsk/c1t2d0s1 swap
BBU UET
Finacle Training
(/dev/dsk/c0t0d0s0 (/dev/dsk/c0t0d0s3 (/proc (fd (/dev/dsk/c0t0d0s4 (/dev/dsk/c0t0d0s6 (/dev/dsk/c0t0d0s5 (/dev/dsk/c0t0d0s7 (/dev/dsk/c1t1d0s0 (/dev/dsk/c1t1d0s1 (/dev/dsk/c1t1d0s3 (/dev/dsk/c1t2d0s0 (/dev/dsk/c1t2d0s1 (swap
): ): ): ): ): ): ): ): ): ): ): ): ): ):
967332 779990 0 0 1190894 2264162 553948 8689026 391628 1208750 2414238 2266602 1498746 2828544
blocks blocks blocks blocks blocks blocks blocks blocks blocks blocks blocks blocks blocks blocks
330533 224501 7862 0 366000 322103 356316 1014784 828668 754741 397829 1508165 417826 171037
files files files files files files files files files files files files files files
kbytes used avail capacity 640967 157301 425979 27% 1018191 628196 328904 66% 0 0 0 0% 0 0 0 0% 721335 125896 537733 19% 3099287 1967206 1070096 65% 721335 444361 219268 67% 8572345 4227844 4258778 50% 8261393 8065579 113201 99% 6196234 5591859 542413 92% 2940743 1733624 1148305 61% 12390920 11257619 1009392 92% 5022314 4272941 699150 86% 1417912 3640 1414272 1%
Mounted on / /usr /proc /dev/fd /var /oracle /opt /users /wd /database2 /wd2 /database1 /wd1 /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:
UNIX Fundamentals
Ver. 1.01
Page 27
Infosys Document
$ du 2 22 174 244 828 836 14 16 18 14 2 2 6 974 32738 274 2 396 28 16 132258 ./tmp ./web/images/_vti_cnf ./web/images ./web ./index/temp ./index ./.fm/users/balu1 ./.fm/users ./.fm ./.bin ./database/utidb ./database/utiarch ./database ./sql ./gary ./TMP ./.wastebasket ./scripts ./tape ./menu .
BBU UET
Finacle Training
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 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.
UNIX Fundamentals
Ver. 1.01
Page 28
Infosys Document
BBU UET
Finacle Training
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, 1 2 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.
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.
UNIX Fundamentals
Ver. 1.01
Page 29
Infosys Document
BBU UET
Finacle Training
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.
INVOKING VI
COMMAND vi vi <filename> FUNCTION Starts an empty edit buffer. Edits the file <filename> or creates the file <filename> if it does not vi +3 <filename> vi + /bye exist. Opens the file <filename> and goes to the third line. Searches for the first occurrence of bye in the file <filename>.
<filename>
k or (Up arrow)
Ver. 1.01 Page 30
UNIX Fundamentals
Infosys Document
BBU UET
Finacle Training
h or Bkspc
vi
j or + or Enter
l or spc bar
All vi commands involve the use of alphabetical keys, alone or in combination with Shift and Control Keys.
but
ignores
punctuation Goes to the beginning of a line Goes to the end of the line Go to the line number # of the file Go to the last line
SCREEN COMMANDS
COMMAND Ctrl-F Ctrl-B Ctrl U Ctrl-D Ctrl R or Ctrl L FUNCTION Scrolls a screen forward except last two lines Scrolls a screen backwards Scrolls forward by half a screen Scrolls backwards by half a screen Re-draw and clear messages
UNIX Fundamentals
Ver. 1.01
Page 31
Infosys Document
Ctrl-G
BBU UET
Status of edit
Finacle Training
DELETING DATA
COMMAND #dd #dw #dW #x #X d$ or D d0 FUNCTION Delete current line where cursor is present Delete words from the cursor position Same as #dw but includes punctuation Delete character at the cursor position Delete character before the cursor Delete current line from the cursor position to the end of the line Delete current line from the position up to start of line cursor
TEXT INSERTION
COMMAND I I O o a A FUNCTION Invokes insert mode and inserts before character Same as i but insertion at
beginning of line Opens a blank line above current line Opens a blank line below the current line Same as i but inserts after cursor 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 Multiple lines copy $ for last line, 1,3 is range :2co5 :1,3co$
UNIX Fundamentals
Ver. 1.01
Page 32
Infosys Document
Move to line 6
BBU UET
Finacle Training
:6 3dd
Delete three consecutive lines now (#dd) Yet another way Symbol . + - Means Current line
where cursor is Line after current line Line current line before
Delete 3 lines after current line Delete 3 lines below current line including current line , denotes range Move line 1 to after line 3 Lines 1,2 and 3 after line 5
: .+3d :.,+3d
: 1mo3 : 1,3mo5
changes Save and quit Replace old copy with new and quit Save and Quit command mode) (from
UNIX Fundamentals
Ver. 1.01
Page 33
Infosys Document
C cc
BBU UET
Finacle Training
Same as cw but acts on rest of line from current cursor position Same as C but entire line
9 LIVES !
vi offers undo of upto 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
All line, word and character commands can be used while yanking
dk - deletes block from mark k upto current cursor position ayk - yanks into register a ap - puts contents of a
PATTERN SEARCHING
Basic commands are : /g search for pattern g forwards
UNIX Fundamentals
Ver. 1.01
Page 34
Infosys Document
?g n
BBU UET
search for pattern g backwards repeat the last / or ? command
Finacle Training
SUBSTITUTION
These are : (colon) commands. To replace string by string1 on the current line :s/string/string1/ :s/string/string1/g - replaces only first occurrence - 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 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
UNIX Fundamentals
Ver. 1.01
Page 35
Infosys Document
BBU UET
Finacle Training
UNIX Fundamentals
Ver. 1.01
Page 36
Infosys Document
BBU UET
Finacle Training
[file1] file2 file3 -i.e. rew rewinds to file1 :rew! :e file - discards changes and coercively rewinds - edits file outside chosen list but :args will not show this file in list
The more common options are: SET COMMAND :set number,nu :set showmode :set autowrite,aw :set autoindent,ai :set beautify,bf :set directory,dir :set :set :set :set :set :set :set :set :set :set :set errorbells,eb ignorecase,ic magic mesg redraw scroll shell term terse warn window DEFAULT nonumber noshowmode noaw noai nobeautify dir-/tmp noeb noic magic nomesg noredraw scroll=half window sh=/bin/sh value of TERM noterse warn window speed ws wm=0 nowa DESCRIPTION Line numbers Display vi mode Save on n, rew, ! Indent as first line Control characters omitted Sets temporary
directory No error beep Uppercase as lowercase Allow all metacharacters Inhibit Write messages Act as intelligent terminal No. of lines to scroll Set which shell Set which terminal Error messages terse Warn save on Shell Esc No of lines in text window Wrap pattern on find Blank screen margin right Allow writes freely
UNIX Fundamentals
Ver. 1.01
Page 37
Infosys Document
The .exrc file
BBU UET
Finacle Training
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
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.01
Page 38
Infosys Document
BBU UET
Finacle Training
QUIZ
TOPIC: UNIX AND vi EDITOR Srl.No. 1. 2. 3. 4. 5. 6. 7. Question
Operating system is an interface between user and computer Unix is a multiuser and non multitasking operating system Operating system takes care of housekeeping activities The unit which interacts with user is called KERNEL Shell is a core unit in unix system Unix treats all the devices as files 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 ls is a list command vi is one of the editors in unix console is a monitor connected to server Whenever a new user is created in unix his/her details are entered in /etc/passwd file System administrator can see users password One general user can change another users password Users can change their passwords All the unix commands work on all platforms
True
False
QUIZ
Page 1
Infosys Document
BBU UET
Finacle Training
EXERCISES TOPIC :
Sl.No What is meant by multitasking? 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. What is the output of ls command? How to create a directory? What does rm <filename> do? How to remove a directory? What is the command used for copy? How to change the ownership? How to find out the users logged in? Which command is used for pattern matching? What is the prompt you get when you login as superuser(root)? How do you use mount command? What does tar command do? How do you find out the space occupied in the file systems? How do you find out the space available in all file systems? What are the roles of system administrator?
UNIX FUNDAMENTALS
QUESTION
EXERCISES
Page 1