Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 48

Chapter 1

Understanding and usage of


Operating System

1.0 Introduction
Without software, a computer is basically a useless lump of metal. With its software,
a computer can store, process and retrieve information and engage in many other valuable
Activities to earn its keep. Computer software can be divided roughly into two kinds:
System program, which manage the operation of the computer itself, and application
programs, which perform the actual work the user wants. The most fundamental system
program is Operating System, which controls all the computer resources and provides
the base upon which the application program can be written.
A modern computer system consists of one or more processors, some main memory,
disk, printers, network interfaces and oth er input/output devices. It is all in all, a complex
system. Writing p rograms correctly, is an extremely difficult job. If every programmer
had to be concerned with how disk drives wo rk, and with all things that could go wrong
when reading a disk, it is unlikely that many programs could be written at all.
Some way had to be found to shield programmers from the complex ity of the
hardware. The way that has evolved gradually is to put a layer of software on top of bare
hardware to manage all parts of the system. This layer of software is the Operating
System.

The situation is shown in the following figure. At the bottom hardware, which
composes two or more layers. Lowest layer contains physical devices, consisting of
Integrated circuits chips, wires, power supplies, CRT and similar physical devices.

Next comes primitive software that directly controls these devices. This software is
called Microprogra m usually located in Read Only Memory. The set o f instructions that
the microprogram interprets defines the Machine Language.
In this layer Input / Output devices are controlled by loading values into special
device registers. Next layer is operating system. The major function of the operating
system is to hide all this complexity and give the programmer a more con venient set of
instructions to work with. On top of the operating system is the rest of the system
software. Here we find, Command Interpreter (Shell), Window system, Compilers,
Editors and similar application independent programs.

Finally above the system progr ams come the application programs. These programs
are purchased or written by the users to solve their particular problems for Ex: Word
processing, Spreadsheets, Engineering Calculations, Games etc.
1.1 What is an Operating System

An Operating system is a program that controls the execution of application


programs and acts as an interface between the user of a computer and the computer
hardware. An Operating system mainly performs three functions
• Convenience : It makes computer more convenient to use

• Efficiency : It allows the computer system resources to be used in an efficient


manner

• Ability to solve: It should be constru cted in such a way as to permit the


effective development, testing and introduction of new system functions
without at the same time interfacing with service.

The Operating system typically provides services in the following areas :


• Program Creation: Operating system services editors and debuggers, to
assist programmer in creating programs.
These services are in the form of utility programs that are accessible through
the Operating System.

• Program Execution: Program execution needs instructions and data to be


loaded in to main menu, Input / Output devices and files to be initialized and
other resources to be prepared. The operating system handles all these
tasks for the user.

• Access to Input / Output devices: Each Input / Output device requires its
own peculiar set of instructions of control signals for operation.
Operating system takes care of details so, the programmes can think in terms
of simple read and writes.

• Controlled access to files: Operating system provides protection mechanisms


to controlled access to files

• System Access: Operating System controls access to the system as a whole


and to specific system resources.

• Error detection and response: Variety of errors can o ccur which a computer
system is running, i.e., internal and external hardware errors, such as memory
error, device failure error, various software errors, inability of Operating

System to grant request of an application errors and so on. In each case,


Operating System must make the response that clears the error condition. The
response may range from ending the program that caused the error, to retrying
the operation to simply reporting the error to the application.

• Accounting : A good Operating System collects usage statistics for various


resources and monitors performance parameters such as response time, which
can be used for billing purposes on a multi-user system.

Operating System as Resource Manager:


A computer is a set of resources, the operating system is responsible for managing
these resources. Operating System controls the movement, storage and processing of
data. Operating system functions in the same way as ordinary computer software. i.e., it
is a program executed by the processor. This frequently relinquishes control and must
depend on processor to allow it to regain control.
Operating System is nothing more than the computer program. This provides
instructions to processor like other programs do. Main diff erence between Operating
System and other programs is, Operating System directs the processor in the use of the
other system resources and in the timing of its execution of other programs.
1.3 History of Operating System:
• First three digital computers were designed by English Mathematician
Charles Babbage in 1792-1871. It was purely mechanical design.

• After Babbage’s efforts little progress was made in constructing digital


computers. In (1945-1955) First Generation Computers with Vacuum
tubes and plug boards were evolved. In these d ays a single group of people
designed, built, programmed, operated and maintained each machine.
Programming was done in Machine Language.

• Second Generation (1955-65) Transistors and B atch System. Here for the
first time between the programmers and maintenance persons, Transistors
were introduced. To run a job, a programmer would first write the program on
paper, then punch it on cards, bring the card deck down to Input / Output
room batch system was to collect a tray full of jobs in the Input / Output room
and then read them onto a magnetic tape just to reduce the wasted time.

• Third Generation (1965-1980) Integrated Chips and Multiprogramming


In this generation, Integrated circuits were used, providing a major
price/performance advantage over second generation machines, which were
built up from individual transistors. Concept of Multiprogramming was
introduced. When the current job was to wait for a tape or other Input / Output
operation to complete the Central Processing Unit simply sat idle until the
Input / Output finished. As the Central Processing Unit time is very precious
this wasted time is not significant. The solution was to partition menu into
several pieces, with a different job in each partition as shown in the figure
Job3 below:
Job2
Job1
Operating System
Job3

Job2

Job1

Operatin g System

While one job was waiting for Input/Output to complete, another job could be
using the Central Processing Unit. Therefore, if enough jobs could be held in
main menu at once, Central Processing Menu could be kept busy nearly 100%
of time. This concept is called as Multiprogramming.
Another major feature in Third Generation System was the concept of time
sharing, in which each user has an On-line terminal. As multiprogramming
allows the processor to handle multiply and batch jobs at a time, the processor
time is Shared among multiple users in time sharing systems. The basic idea
for time sharin g system is to have multiple users Simultaneously using the
system with the Operating System inter leaving the execution of each user
program in a sho rt burst of computation. Thus if there are n users actively
requesting service at one time, each user will see on average only 1/n of
effective computer speed. The following figure shows Multiprogramming
with two programs:

5
Program A Run Wait Run Wait

Program B Wait Run Wait Run

Combined Run A Run B Wait Run A Run B Wait

• Fourth Generation (1980-present): Personal Computers: With the


development of LSI (Large Scale Integration) circuits, chips containing
thousands of transistors in a square centimeter of silicon, the age of personal
computers dawned. Personal Computers are not that different from mini
computers. The most powerful Personal Computers used by business,
universities and government installations are usually called Work Stations
(Large Personal Computers). Usually they are connected together by
hardware.
An interesting development that began during middle 1980’s is the growth of
hardware of Personal C omputers running hard ware Operating System and
distributed Operating System. In hardware Operating System, the users are
aware of the existence of multiple computers and can log in to remote
machines and copy files from one machine to another.

1.5 Operating System Concepts:


Operating Systems are among the most complex pieces of software. Five major
achievements in the development of Operating System are
• Process

• Memory Management

• Scheduling and Resource Management

• Information protection and security

• System Structure

6
• Processes : It is somewhat more general term than job. Process is a program
that is in execution. Three major lines of computer system development
created problems in timing and synchronization that contributed to the
development of the concept of the process. Multiprogramming batch
processing, time sharing and real time transaction. The design of system
software to co-ordinate the various activities turned out to be difficult. With
many jobs in progress at any one time, each of which involved numerous steps
to be performed in sequ ence, it b ecame impossible to analyze all the possible
combination of sequences of events. So many errors were detected which
were difficult to diagnose because they needed to be distinguished from
application software errors and hardware errors. To tackle these problems, it is
required to monitor and control the various programs executing on the
processor in a systematic way.

The concept of process provides the foundation process consists of the following
three components.
• An executable program

• The associated data needed by the program

• Execution context of program

Execution context includes the information that the Operating System needs to
manage the process and that the processor needs to properly ex ecute the p rocess.
If two processes A and B exist in a portion of the main memory, each process is
recorded in process list, which is maintained by Operating System. Process index register
contain the index in to the process list of the process currently controlling the processor,
Program counter points to the next instruction in that process to be ex ecuted. Base and
limit register defines the region in memory occupied by th e process.
Thus process is realized as a data structure. A process can either be executing or
awaiting execution. The entire state of process is contained in its context.

• Memory Management : Users need a computing environment that supports


the flexible use of data, efficient and orderly control of storage allocation. An
Operating System, to satisfy these requirements has five principal storage
management responsibilities as follows:

7
• Process Isolation : Operating System must prevent independent process from
interfacing with data and memory of each other.

• Automatic Allocation and Management : Programs should be dynamically


allocated memory across the memory is required. Operating System can
achieve efficiency by assigning memory to jobs only as needed.

• Support of Modular Programming : Programmers should be able to define


program modules and to create, destro y and alter the size of modules
dynamically.

• Protection and Access Control : Sharing of memory at any level of memory


hierarch y. Operating System must allow portions of memory to be accessible
in various ways b y various users.

• Long term storage : Man y users and application require means for storing
information for extended periods.

Operating Systems meet these requirements with the concept of Virtual Memo ry
and file system facilities. Virtual Memory is a facility that allows program to address
memory from a logical point of view without regard to the amount of main memory
physically available. That is, when a program is executing only a portion of program and
data may actually be maintained in main memory. Other portions of program and data are
kept in blocks in disk itself and will be brought to main memor y whenever its execution
is required.
• Inf ormation protection and security : Operating System must support a
variety of protection and security mechanism to computer system and the
information stored in them. Some overall protection policies are:

• No sharing : In this case, processes are completely isolated from each other
and each process has exclusive control over resources statically or
dynamically assigned to it.

• No sharing originals of program or data files

• Controlled information dissemination : In some systems, security classes are


defined to enforce a particular dissemination policy. Users and applications
are given security clear ances of a certain level, whereas data and other
resources (e.g., I/O devices) are given secu rity classifications. The security

8
policy enforces restrictions concerning which users have access to which
classifications

• Access Control : Is concerned with regulating user access to the total system,
sub systems, and data, and regulating process access to various resources and
objects within the system

• Information flow control : Regulates the flow of data within the system and its
deliver y to users

• Scheduling and Resource Management : A key task of the Operating


system is manage the various resources available to it (main memory space,
I/O devices, processors) and to schedule their use by the various active
processes. An y resource allocation and scheduling policy must consider the
following three factors :

• Fairness : Typically, we would like all processes that are competing for the
use of a particular resource to be given approximately equal and fair access to
that resource. This is especially so for jobs of the same class, that is, jobs of
similar demands, which are charged the same rate.

• Differential responsiven ess : On the other hand, the operating system may
need to discriminate between different classes of jobs with different service
requirements. The operating system should attempt to make allocation and
scheduling decisions to meet the total set of requirements. The operating
system should also view these decisions dyn amically. For example, if a
process is waiting for the use of an I/O device, the operating system may wish
to schedule that process for execution as soon as possible to free up the device
for later demands from other processes.

• Efficiency : Within the constraints of fairness and efficiency, the operating


system should attempt to maximize throughput, minimize response time, and
in the case of time sharing, accommodate as many users as possible

The operating system maintains a number of queues, each of which is simply a list of
processes waiting for so me resource. The short-term queue consists of processes that are
in main memory (or at least an essential minimum portion is in main memory) and are
ready to run. Any one o f these p rocesses could use the processor next. It is up to the

9
short-term scheduler, or dispatcher, to pick one. A common strategy is to give each
process in the queue some time in turn; this is referred to as a round-robin technique.
Priority levels may also be used. The lon g-term queue is a list of new jobs waiting to use
the system. The operating system adds jobs to the system by transferring a process from
the long-term queue to the short-term queue. At that time, a portion of main memory
must be allocated to the incoming process. Thus, the operating system must be sure that it
does not over-commit memory or processing time by admitting too many processes to the
system. There is an I/O queue for each I/O device. More than one process may request
the use of the same I/O device. All p rocesses waiting to use each device are lined up in
the device queues. Again, the operating system must determine which pr ocess to assign
to an available I/O device. The operating system receiv es control, of the p rocessor at the
interrupt handler if an interrupt o ccurs. A pro cess may specifically invoke some operating
system service, such as an I/O device handler, by means of a service call. In this case, a
service-call handler is the entry point in to the operating system. In any case, once the
interrupt or service call is handled, the short-term scheduler is invoked to pick a process
for execution.

System Structure
As more and more features have been added to operating systems and as the
underlying hardware has become more complex and versatile, the size and complexity of
operating systems has grown. The size of a full-featured operating system and the
difficulty of the task it addresses have led to three unfortunate but all too common
problems. First, operating systems are chronically late in being delivered. This goes for
new operating systems and for upgrades of older systems. Second, the systems have
latent bugs that show up in the field and must be fixed and reworked. And finally,
performance is often not what was expected. To manage the complexity o f operating
systems and to overcome these problems, much attention has been given over the years to
the software structure of the operating system. Certain points seem obvious. The software
must be modular. This helps to organize the software development pro cess and limits the
task of diagnosing and fixing errors. The modules must have well-defined interfaces to
each other, and the interfaces must be as simple as possible. Again, this eases the
programming task. It also makes the task of system evolution easier. With clean, minimal
interfaces between modules, one module can be changed with minimal impact on other
modules.

10
Chapter 1 - EXERCISE
True or False

1. Operating System is a System Software

2. First Generation Computers were purely mechanical

3. Secondary Memory is called Virtual Memory

Fill in the blanks

1. Process is a program that is in ______________

2. Major features of Third Generation System was the concept of ____________

3. The most fundamental system program is ________________

4. Operating System allows _______________________ to be used in efficient


manner

11
Chapter 2
INTRODUCTION TO DOS
Disk Operating System manages your computer’s resources. The part of Disk
Operating System that controls the hardware such as the video screen, keyboard, mouse,
disks and printer is the Kernel. A second part of Disk Operating System that interprets
your commands and causes the kernel to do what you want is called the Command
Interpreter. However, I will use the term command prompt to refer to it since the
prompt is its visible part that you use to communicate with the kernel. More precisely, the
command interpreter converts commands you enter at the command prompt to their
required form and gives them to the kernel.
The Disk Operating System shell is actually an interface between you and the
command interpreter that provides an easy way to enter commands. Each time Disk
Operating System is started, the command prompt is automatically displayed on your
screen. Nevertheless, you can set up your system to have the Disk Operating System shell
automatically displayed instead. Since the Disk Operating System shell is easier to use
than the command prompt. First let’s see which interface is waiting for your command. If
you are working at the command prompt, the last line on the screen looks like this :

C:\>
This line may be the only one on the screen. When the Disk Operating System shell
is first set up and is waiting for your command, the Start Programs screen appears.

Disk Drives and Directories :


A disk drive is a device which runs the disk (floppy or hard) and in the process either
storing data or reading from it. A PC has floppy drives only and th e first floppy drive is
conventionally called drive A: whereas the second floppy driv e is designated as drive B:
Booting is synonymous with starting a computer. When you switch on the computer
first thing in the morning, the computer with instructions from BIOS, which are programs
fused in to ROM, the read only memory of the computer or the firmware, checks the
memory and peripheral routines. Drive A: of a microcomputer is the primary drive,
which a computer looks for first o f all on switching on. It reads the disk in drive A: for

12
any boot record or system files. If drive A: does not have these it goes to the drive C:,
skipping drive B: as per specific B IOS instructions, to read the same. On finding these
the computer starts the process of loading DOS in to the RAM of the computer. Once th e
DOS is loaded it is said that the DOS has been booted and the computer is ready to accept
your order. The following prompt stares at you and awaits your orders:
A>_ or C>_ will be displayed along with a flashing cursor depending upon whether
the system has been booted from A: or C: drive. When you boot from A: drive DOS
diskette must be in driv e A: snu gly inserted with drive door properly closed otherwise
disk in drive A: will not be read. When you boot from C: drive DOS must be previously
installed in the hard disk so that the system files are duly loaded in to RAM.
MS-DOS is a command-driven operating system. This means that there are a set of
commands which you give to the operating system for the tasks you wish it to perform.
These commands are entered in front of the System Prompt (A, or B, or C..) at the place
you see the blinking “hyphen” which is the cursor. After you enter the command you
press the {Return} key to record your command. Until you press {Return} you can
correct any typo gr aphical mistakes that you may hav e made while entering your
command. The line at which you enter your command is called the Ms-DOS Command
Line.
A> tells you the current default drive. Unless overridden by the command, DOS will
search this drive for all files. To change the default drive, simply enter the drive desired
as follows:

drive: (for example B: or C: or A: and Press {Return}

The DOS FORMAT command performs several functions. Firstly, the FORMAT
command converts an off-the-shelf disk to a disk that DOS can use. Secondly, FORMAT
can make a disk bootable by DOS if you use the /S qualifier in the FORMAT command.
Thirdly, FORMAT places a list of damaged disk locations on the disk so that DOS will
not try to use those locations to store data. Lastly, FORMAT allows you to specify a
volume label. Give the following command to format diskette in drive B:

A>format B:_ <Return>

DOS files names are of the form

Filename.txt

13
The file name must contain one to eight characters. The extension is optional and, if
present, must contain from one to three characters. A period separates the file name from
the extension. The following are valid DOS file names:

CHAPTER.TXT NOTES.DAT MATH.HW

SCIENCE.RPT DO_TODAY EXPENSES.$$

Letter.Jan Personal Off_Jan.10


DATA….DAT is illegal because of the two periods. The file name and extension
are separated by a period, which makes the period an illegal character in DOS file names.
NEW.DATA is illegal because of extension DATA is more than three characters
in length. The extension on DOS file names is optional and if present, must contain from
one to three characters
DOSFILENAME.DAT is illegal because the file name portion of a DOS file name
can not exceed eight characters.
CON.DAT is illegal because CON is a DOS device name. DOS reserves several
names for the devices that are attached to your computer. The followin g are illegal DOS
file names on account of these being reserved desired names:
AUX CON LPT3 CLOCKS LPT1 LPT2 NUL COM1 COM2
The .234 is illegal because it lacks a file name. Only the three-char acter extension in
DOS file names is optional.
By directory is meant the list of files and/or sub-directories that are present in a
floppy disk or hard disk.
The DOS directo ry command DIR lists the files on a disk.
A> DIR {Return}
DIR/p <Return> It displays the directory page wise, P represents pause so a screenful
with 80 columns by 23 lines is displayed. If the entries are more th an 223 lines the
computer will prompt you “Strike a key when ready ………..”. On pressing any key the
next portion of 23 lines will be displayed. The display will show the primar y file name,
the extension, the space used, the date and the time of creation of the file. At the end of
the director y listing it will also show the total number of files and the n umber of free
bytes of space available.

14
DIR/W <Return> The above displays the files and directory entries across the screen
with W standing for “wide view”. This way you can get more file names on the screen at
one time. However, the display will consist of only p rimar y name and extension, if any. It
will not <Dir> entry no r it will give the space used and the d ate and time of creation of
individual files. The command is used to quickly browse through the list of all files
present in a disk or directory.
A>DIR *.EXE You will see all the files having extension .EXE will be displayed.
A>DIR S*.EXE You will see all the files having primary name which starts with S
and with extension .EXE will be displayed.
C:\>DIR A: <Return> is the command from drive C to see directory of disk in drive
A.
C:\>DIR C: <Return> is the command to see the d irectory of C:.
C:\>DIR *. <R eturn> is the command to see the names of just the sub directories
present in the root directory of the hard disk C.
C:\> DIR FILENAME.* <Return> is the command to display the files having the
same primary name (say FILENAME) but different extension.
C>DIR ???A.?B? The above command will search for all files that have a primary
name of 4 characters with the fourth character as A and an extension of 3 characters with
the middle character as B.? is a character which represents an y single character in a file
name. This technique is used to search those files whose full names are not known or are
temporarily forgotten. ? is called a wild card ch aracter.
C:\>DIR *.* Represents all the characters of the primary file name if it is written
prior to the extension dot. If entered after the extension dot it represents all the characters
given to the extension. Thus the above command will show all the files located in C
drive. The difference between ? and * is only that where as ? represents single character,
* represents all characters. * is also called a wild card character.
A:\>COPY COMMAND.COM B: {Return} is the command to make a cop y of the
file COMMAND.COM from drive A to B.

BASIC DOS COMMANDS


1. ANSI -- Allows color to be added to the video display
Format DEVICE=C:\DOS\ANSI.SYS

15
2. ASSIGN -- Changes the name of a disk drive
Format ASSIGN A = C
ASSIGN A=C;B=C
Assign

3. ATTRIB – Displays and changes read-only and archive attributes of a disk file
Format ATTRIB +R ambig
ATTRIB –R ambig
ATTRIB +A ambig
ATTRIB –A ambig
ATTRIB +A + R ambig /S
ATTRIB

4. BACKUP – Makes a flopp y-disk backup of your hard disk


Format BACKUP C:\*.* A:/S
BACKUP C:\ambig A:/S/M

5. BREAK – Allows program termination if you type ^ Break


Format BREAK ON
BREAK = ON
BREAK

6. CD (OR CHDIR) – Changes the current directory at the command prompt


Format CD\
CD\EDIT
CD SPELL
CD ..
CD

7. CHKDSK – Analyzes and summarizes the state of a disk


Format CHKDSK C:
CHKDSK C:/F
CHKDSK C:/V
CHKDSK PNAME.EXT

8. COMP – Compares two disk files


Format COMP ambig1 ambig2
COMP A: B:
COMP

9. CONFIG – Configures DOS on startup


Format (Executes automatically on startup)

10. DATE – Displays and sets Date

16
Format DATE
DATE 6-9-89

11. DEL (OR ERASE) – Deletes disk files


Format DEL PNAME.EXT
DEL ambig

12. DISKCOMP – Compares two floppy disks


Format DISKC OMP A: B:
DISKCOMP A: A:

13. DISKCOPY – Duplicates a complete flopp y disk


Format DISKC OPY A: B:
DISKCOPY A: A:

14. EDLIN – Creates and alters a text file


Format EDLIN
EDLIN PNAME.EXT
EDLIN PNAME.EXT D
15. ERASE – (See DEL)

16. EXIT – Returns you to the DOS shell from the second command prompt
Format EXIT

17. FASTOPEN – Starts programs quicker


Format FASTOPEN C:
FATOPEN C:=50
FASTOPEN C:/X

18. FDISK – Prepares a new hard disk


Format FDISK

19. FIND – Searches for a pattern of letters in text


Format FIND “string” PNAME.EXT

20. INSTALL – Installs resident programs on startup


Format INSTALL = C:\DOS\FASTOPEN.EXE C:
INSTALL = C:\UTIL\MOUSE.COM

21. LABEL – Changes the name of a disk


Format LABEL B:RECEIPTS
LABEL B:

22. MD (OR MKDIR) – Creates a subdirectory


Format MD\EDIT

17
23. MEM – Displays amount of total and available memory
Format MEM
MEM /PROGRAM

24. MODE – Configures the video screen and serial ports


Format MODE COM1:2400,N,8,1,P
MODE LPT1:=COM1
MODE LPT1
MODE N

25. MORE – Stops scrolling when the screen is filled


Format |MORE
MORE <PNAME.EXT>

26. PATH – Establishes a search path for program execution


Format PATH C:\DOS
PATH D:\;C:\DOS
PATH
PATH;

27. PRINT – Prints a disk file


Format PRINT /D:PRN
PRINT /D:COM1
PRINT
PRINT/T
PRINT PNAME.EXT/C

28. PROMPT – Changes the command prompt


Format PROMPT $P$G
PROMPT $P,$D$G
PROMPT
PROMPT $E[ 0;30;46m $P$G$E[1;37;44m

29. RD (OR RMDIR) – Deletes a subdirectory


Format RD\SUBDIR
RD SUBIDR

30. REN (OR RENAME) – Renames a disk file


Format REN OLDNAME.EXT NEWNAME.EXT
RUN ambig1 ambig2

31. REPLACE – Selectively copies files


Format REPLACE A:*.* C:/A
REPLACE A:*.* C:/U

32. RESTORE – Restores the hard disk from floppy disk backups

18
Format RESTORE A: C:\*.* /S
RESTORE A: C:\*.* /S/N
RESTORE A: C:\LOTUS\*.* /S
RESTORE A: C:\*.* /S/A:2-4-89
RESTORE A: C:\*.* /S/B:2-4-89

33. SET – Changes and displays the current state of DOS features
Format SET COMSPEC=C:\COMMAND.COM
SET
SET SPOOLER = 48K

34. SORT – Sorts lines of a text file


Format SORT <FILE1> FILE2
DIR|SORT /R+10|MOR E

35. SUBST – Establishes a subdirectory as a separate disk


Format SUBST D: C:\EDIT
SUBST D:/D

36. SYS – Writes DOS system to disk


Format SYS
SYS C:

37. TIME – Displays and allows alteration of time


Format TIME
TIME 13:7

38. TREE – Displays subdirectory paths at the command prompt


Format TREE

39. TYPE – Displays a text file on the video screen


Format TYPE PNAME.EXT
TYPE PNAME.EXT>PRN
TYPE PNAME.EXT|MORE

40. VDISK – Establishes a RAM disk


Format DEVICE=VDISK.SYS 256
DEVICE=VDISK.SYS 512/E
DEVICE=VDISK.SYS 512/X

41. VER – Displays DOS Version


Format VER

42. VERIFY – Verifies that a disk file is correctly written


Format VERIFY ON

19
VERIFY = ON
VERIFY

43. VOL – Displays the disk name and serial number


Format VOL
VOL A:

44. XCOPY – Makes backup copies of files


Format XCOPY C:\DOS\*.* /M
XCOPY C:\DOS\*.* /A
XCOPY C:\DOS\*.* /D:8-9-89
XCOPY C:\DOS\*.* /P
XCOPY C:\DOS\*.* /W
XCOPY A:*.* /S

20

UNIX

STRUCTURE

4.1 INTRODUCTION
4.1.1 Wh y you must know UNIX Today
4.1.2 History of UNIX
4.1.3 Popularity and Success of UNIX

4.2 ARCHITECTURE OF UNIX


4.2.1 What Ex actly is UNIX
4.2.2 System Architecture

4.3 FILE SYSTEM


4.3.1 File System
4.3.2 Tree Structure
4.3.3 Directories
4.3.4 Operating System Services
4.4. GETTING STARTED
4.4.1 Account and Password
4.4.2 Logging In
4.4.3 Shell

92
Chapter 4
INTRODUCTION

Objectives:
After completing this chapter, you will the able to:
• List 3 important phases of UNIX

• Understand why UNIX popular

• History of UNIX

UNIX consists of a large number of ideas, too man y for a sin gle person to master in
a lifetime.

4.1.1 Why you must know UNIX Today


UNIX had to grow through 3 important phases in its life cycle. First reason, it was
considered a product for the Engineering and Scientific community. Later, it made
significant inroads into large Corporations and Government Organizations where its
robustness established it on the operating system of choice for database work (Ex ample
Oracle, Sybase & Informix ) The Inter net is the third and most significant phase of the
UNIX cycle. Even though the people say that UNIX was died, most servers on the net are
UNIX machines. Internet Service Providers use UNIX machines.

4.1.2 History of UNIX


In 1965, Bell Telephone Laboratories joined an effort with the General Electric
Company and Project MAC of the Massachusetts Institute of Technology to develop a
new operating system called Multics. The goals of the Multics system were to provide
simultaneous computer access to a large community of users, to supply ample
computation power and data storage, and to allow users to share their data easily, if
desired. Many scientists later took part in the early development of the UNIX system. In
1969, Bell laboratories ended its participation in the project.

93
Later Ken Thompson, Dennies Ritchie, and other s sketched a paper design of a file
system that it evolved into an early version of the UNIX file system. Although this early
version of the UNIX system held much promise, it could not realize its potential until it
was used in a real project. Ritchie has developed a new lan guage called ‘C’, and in 1973,
the UNIX operating system was rewritten in C.
In January 1983, Bell Laboratories added several features to UNIX system III and
called a new product UNIX System V, and AT & T announced official support for
System V.

4.1.3 Popularity and Success of UNIX


Unlike DOS and Windows UNIX can be used by several users concurrently. The
UNIX is popular for the following reasons:
• The system is written in a High Level Language, making it easy to read,
understand, change, and move to other machines.

• It uses a hierarchical File System that allows easy maintenance and efficient
implement

• It has a simple user interface that has the power to provide the service that
users want.

• It provide a simple, consistent interface to peripheral devices.

• It is a multi-user, multiprocessor System, each user can execute several


processes

• simultaneously.

• It hides the machine architecture from the user, making it easier to write
program that run on different Hardware implementations.

• UNIX is a multitasking operating system, You can be perfo rming two tasks

• simultaneously.

• UNIX has networking built in environment.

94
If you are migratin g from the DOS/ Windows environment, then you have quite a bit
of mental preparation to do before you start feeling comfortable. That is, UNIX is not
ver y friendly.

Exercise 4.1:
1. Give three important reasons of UNIX

2. When UNIX system III released

3. Name the Scientist who give the paper discover of or File system

4.2 ARCHITECTURE OF UNIX

Objectives:
After completing this section, you will be able to :

• List Operating system functions

• Draw UNIX system architecture

4.2.1 What Exactly is UNIX


UNIX is an operating system in the same way MS-DOS and OS/2 are Operating
System. An operating system performs many fun ctions:

• It actually runs a program: When you enter a program‘s filename at the


command line the operating system takes over by loading the program into
your computers memory and runs it.

• It controls all input and output on the computer: When you delete a file,
the operating system goes ahead and eliminates a record of that file. When
you save a file, the operating system makes sure yo ur file isn’t written on top
of an existing file.
4.2.2 System Architecture:
UNIX carries out various functions through 3 separate, but closely integrated parts:
the File System . the shell, and the kernel. The responsibilities are given below:
• the kernel is responsible for all basic operating system functions.
• the File System tracks files and wher e they are located. Every thing on UNIX,
whether it’s a file created in a text processor or a driver used to send
instructions to a pointer is contained in a file.
• the shell or command-line interpreter, is the part of UNIX you will actually
• be using most of the time.

nroff sh
cpp who

CC comp a.out
H/W
as date
Kernel
wc ld
ed grep

Figure 1 depicts the high-level architecture of the UNIX system.


The hardware at the center of the diagram (see Figure1) provides the operating
system with basic services.
The operating system interacts directly with the hardware, providing common
services to pro grams, viewing the system as a set of layers. The operating system is
commonly called the system kernel or just the kernel.
Programs such as shell and editors (ed and vi) shown in the outer layers interact with
the kernel, by invoking a defined set of system calls. The system calls instruct the kernel
to do various operations for the calling program and exchange data between the kernel
and the program.
Several programs shown the figure 1 are in standard system configurations and are
known as commands.
Others application pro gr ams can build on top of low-level programs. For example,
the standard C compiler cc is in the outermost layer of the kernel: it involves a C
preprocessor, assembler, and loader, all separate lower-level programs.
Many application subsystems and programs that provide a high-level view of the
system such as the shell, editors, and document preparation packages, have gradually
become synonymous with the name “UNIX System”.
4.3 FILE SYSTEM

Objectives:
After completing this section, you will be able to:

• List UNIX File system characters

• Under stand file system hierarchy

• List- operating services

4.3.1 File system


The UNIX file system is characterized by
• a hierarchical structure

• consistent treatment of file data

• the ability to create and delete files

• dynamic growth of files

• the protection of file data

• the treatment of peripheral devices as files

4.3.2 Tree Structure


The file system is organized as a tree with a single root node called rod (“/”) (see
figure 2) ever y non leaf node of the file system structure is a directory of files, and files at
the leaf nodes of the tree are either directories, regular files, or special device files.

The name of the file is given by a p ath name that describes how to locate the file in
the file system hierarchy.

98
console
spell
div ….
bin troff
……
------

telnet sh
ucb man
bin csh
…….
……

bin
libc.a
local
lib lib
….

/ usr include

kra tmac

lib troff
user pes

-----
…..

passwd tmp
etc gr oup

init
…..

tmp

Figure 4.2: Typical UNIX directory structure

99
A path name is a sequence of component names separated b y slash(/) characters.

Example:
“/etc/password”, “/usr/ucb/telnet”, “/home/Anand”. etc . A full p ath names start is a
slash (‘/‘) ch aracter and specifies a file that can be provided by staring at this file system
root and traversing the file tree.

4.3.3 Directories

Directories are like regular files the system treats this data in a directory as a byte
stream, but the data contains the names of the files in the directory.

Permission to access a file is controlled by access permissions associated with the


file. Access permission can be set independently to control read, write, and execute
permission.

Permission is given three classes of users: the file owner, a file group, and every
one else. You may create files if directory permission is given.

Devices are also protected in the same way that regular files are protected.

Generally, the system calls allow uses to write programs that do sophisticated
operations and as a r esult, the kernel of the UNIX system does not contain many
functions that are part of the “kernel” in their systems.

The shell allows 3 types of commands. First, a command can be an executable file
that contains object code produced b y compilation of source cod e (a C program for
example). Second, a command can be an executable file that contains a sequence of shell
command lines. Finally, a command can be internal shell command.

The shell searches for commands in a given sequence o f directories, changeable by


user/invocation of the shell. The shell usually execution a command syn chronously,
waiting for the command to terminate before reading the next command line.

100
4.3.4 Operating System Services
Among the services provided by the kernel so (Figure 1) are:
• controlling the execution of process b y allowing their creation, termination or
suspension, and communication.

• Scheduling process fairly for execution on the CPU.

• Allocating main memory for an executing pro gr am

• Allocating secondar y memory for efficient storage and retrieval of user data.

• Allowing processes controlled access to peripheral devices such as terminal


tape drives, disk drives, and network devices.

Exercise 4.3:
1) List at least 3 characters of UNIX file system

2) What is root?

3) Check whether the following statements True/False


a) Leaf nodes are directories
b) Leaf nodes are special device files

4) What is path give one example

5) Who allocate main memory for pro gram ex ecution

6) Who control access to peripheral devices

4.4 GETTING STARTED

Objectives:
After completing the section, you will be able to:

• Understand what is Account and Password

• Understand One job of system administrator

• Understand login procedure

101
• Know what is shell

• List different shells

4.4.1 Account and password


UNIX is security- conscious, and can b e used only b y those persons who maintain an
account with the computer system .You can’t simply sit down at any terminal and start
working as in DOS/Windows.
If you are using a UNIX workstation, you must set up your own user account.
System administrator will grant you that authority. He opens an account with the name
(is known as login name/user name) for your use, and given you a secret code called
password that you have to enter when the system prompts you for it.

4.4.2 Logging In
Logging in is a simple procedure that tells the UNIX system who you are:

$ login:

The login prompt indicates that the terminal is available fo r some one to login (i.e
connect). This message also indicates that the previous user has “logged out”
(disconnected).
Enter your user name (or login name) and hit the <Enter> key after the string:
$ login : Type user name <Enter>
Password:

The system now, request you to enter the secret code (password) that was handed
over to you by your administrator. T his code should be known to none except yourself.
Enter your password. The terminal do es not display what you type. Then press the
<Enter> k ey.

Example:
$ login: Anand <Enter>
Password:*******<Enter>

102
The system cross check this password and if it is right you will be presented with a
login sequence like the following:
Welcome to SCO system v/386
Login:
Password:

If you are logging onto a UNIX system V Release 5, the sequence look like this:
Login:
Password:
UNIX system V release AT & T 3B2

System id
Copy right © 1984, 1986, 1987, 1988 AT & T
All Rights Reserved
Last login : Friday March 09 10 :45 : 21 on term /12

If you make mistakes while typing simply press this <Enter> key one or two times
till the login prompt reappears on the screen.
If you enter either of them in correctly, the system flashes the followin g message
Login incorrect
Wait for login retry:

If the login was successful, you will be taken to the $ prompt.

$ This is equivalent of the C:\>

4.4.3 Shell
When you login your UNIX system, you are immediately thrust into your login
shell. Information about this shell is usually contained in this file /etc/password, as in
login into for all this users on your system.
No Command can be executed unless it obtains the clearance of the shell some
popular shells one:

• Sh. the Bourne shell, developed by stephen Bourne in 1979.


• Ksh. korn shell, Developed by David Korn at Bell labs
• Csh the C shell. Developed by Bill joy ( a founder of Sun Microsystems Inc)

103
• Jsh the job shell. An extension of the Bourne shell.
• bash Bourne Again shell. Developed by the Free Software Foundation.

User User

H/W

Kernel
User User
Concepts

Shell

User
Figure 4.3: shows this kernel-shell relationship

Exercise 4.4:
1) What is an account?

2) What is login name or user name

3) What is Password

4) Explain how to login in UNIX

5) Ask your system administrator and create your own account


and then login

6) Who sets the required environment when login is done

7) List different shells

8) Close the book and draw the kernel-sh ell relation ship diagram

104
Chapter 5
LINUX SYSTEM

Structurre
5.1 INTRODUCTION

5.1.1 What you need?


5.1.2 What is LINUX?
5.1.3 Features of LINUX

5.2 GETTING STARTED

5.2.1 Logging in to Red Hat Linux


5.2.2 The login session
5.2.3 The Shell interface
5.2.4 Checking Directories and permission
5.2.5 Exiting the shell

5.3 LINUX FILE SYSTEM

5.3.1 Working with the Red Hat Linux File system


5.3.2 Creating files and directories
5.3.3 Understanding File permission
5.3.4 Moving Copying and deleting files

5.4 vi TEXT EDITOR

5.4.0 Using the vi Text editor


5.4.1 Starting with vi
5.4.2 Moving around the file
5.4.3 Searching for text
5.4.4 Using numbers with command

105
5.1 INTRODUCTION

Objectives:
After completing this chapter, you will be able to:

1. PC configuration needed for LINUX

2. Know what is LINUX

3. Features of LINUX

5.1.1 What you need?


To work with LINUX, you need a Personal Computer with the following general
configuration:

• An Intel 80386, Pentium, or compatible CPU.

• At least 16MB of RAM, although 24MB or more is recommended. To run the


GNOME or KDE desktop, Red Hat recommends 48MB.

• You need 500MB of hard disk space for a typical installation. To install
everything, you need about 1.6GB of space.

• A CD-ROM drive is recommended for installation, although you can install


over a network instead. For that, you need at least a 3.5-inch floppy disk drive
and a network connected to a computer that has the Red Hat Linux software
packages available.

5.1.2 What is LINUX?


LINUX is a free Operating System that was created by Linus Torvalds when h e
was a student as the University of Helsinki in 1991. Torvalds started Linux by writing a
kernel, which is the heart of the operating system, In the 1980s and 1990s, while
Microsoft flooded the world with personal computers running DOS and Windows
operating systems, power users demanded mor e from an operating system. They ached
for system that could run on networks, support many users at once (multiuser), and run
many programs at once (multitasking). DOS and Windows didn’t cut it.

106
5.1.3 Features of LINUX:
• Multi user –Not only can you have many user accounts available on a
LINUX system, but you can also have multiple users logged in and working
on the system, at the same time.

• Multitasking –You can have many programs running at the same time in
LINUX. Besides meaning that you can have lots of programs going at once, it
also means that Linux, itself, can have programs running in the background.
Many of these system processes mak e it possible for LINUX to work as a
server.

• Graphical User Interfa ce (X Window System) –The powerful framework


for working with graph ical applications in Linux is referred to as the X
Window system (or simply X). X handles the functions of opening X-based
GUI applications and displaying them on X server process (the pro cess that
manages your screen, mouse, and keybo ard).

• On top of X, you use an X-based window manager to provide the specific


look-and-feel of your GUI (icons, window frames, menus, and colors). There
are dozens of desktop managers you can choose from. (Red Hat provides
several desktop managers, but focuses on Gnome and KDE.)

• Hardware support –You can configure in support for almost every type of
hardware that can be connected to a computer. There is support for floppy
disk drives, CD-ROMs, removable disks (such as Zip drives), sound cards,
tape devices, video cards, and most anything else you can think of.

• Networking connectivity –To connect your Linux system to a network,


Linux offers supp ort fo r a variety of Local Area Network (LAN) boards,
modems, and serial devices, Ethernet, the most popular protocol TCP/IP
(which is used to connect to the Internet). Oth er protocols, such as IPX (for
Novell networks) and X.25 (a packet-switching network type that is popular in
Europe), are also available.

• Network service-Providing networking services to the client computers on


your LAN or to the entire Internet is wh at Linux does best. A variety of
software packages are available that enable you to use Linux as a print server,

107
file server, FTP server, mail server, web server, news server, or workgroup
server.

• Application support- Because of compatibility with POSIX and several


different application programming interfaces (APIs), a wide range of
freeware.

Exercise 5.1:

Practice the following:


1. Give the general configuration of PC to run LINUX operating system.

2. Is LINUX is a free software?

3. Who wrote LINUX operating system.

4. Mention at least five important features of LINUX system.

5.2 GETTING STARTED

Objectives:
After completing this section, you will be able to:

• Logon to LINUX system

• Understand login session

• Understand shell interface

• List existing shells

This section presents a view of Red Hat Linux from the shell. T he shell is a
command line interpreter that lets you access some of the most critical Red Hat Linux
tools. The shell is powerful, complex, and almost completely unintuitive.

108
This section is your guide to loggin g in and working with Linux system commands,
processes, and file system from the shell. This chapter also describes the shell
environment and helps you tailor it to your needs.

5.2.1 Logging in to Red Hat Linux


Because Red Hat Linux was created as a multi-user computer system, even if you
are the only person using the computer, you start by logging in. Logging in identifies you
as a particular user.
After the computer has been turned on and the op erating system has started, you will
see a login prompt similar to this:

Red Hat Linux release 6.1 (Hedwig)


Kernel 2.2.10-3smp on an i686
l ocal host login:

The graphical login is typically your entry into the X Window System graphical user
interface (GUI).

5.2.2 The login session


As you log on, Red Hat Linux starts up a user environment that is unique to your
user account. Some of the features that make up your user environment are:
• A home directory: The home directory identifies a location on the
computer’s hard disk where you can save and p rotect the files that you need.
The root user’s home directory in Linux is usually root(/). Other users
typically have home directories in the /home directory.

• A shell configuration: There are several shells available for use with Linux,
with each having slightly different features. The bash shell (which stands for
Bourne Again Shell) is most commonly used with Linux.

• A graphical configuration: Most GUIs used with Linux are based on X


Windows system (often referred to simply as X). While X provides a
framework for a GUI th at lets you run applications, it enables you to choose
from many different window managers. The window manager provides the
specific look and feel of the GUI.

109
Once the login process is complete, either a shell or a GUI is started automatically.

5.2.3 The shell interface


Assuming that you are using a shell interface, the first thing you see is the shell
prompt. The default prompt for a user is simply a dollar sign:
$
The default prompt for the root user is a pound sign:
#

5.2.4 Checking Directories and permissions


When you first log in to Linux, you begin with your home directory as the current
directory. When you request to open or save a file, your shell uses the current directory
as the point of reference.
To find out what your current directory is, typ e the pwd command;

$ pwd

/usr/bin
In this example, the current or working directory is /urs/bin. To find out the name of
your home directory, type the echo command, followed by the $HOME variable:

$ echo $HOME

/home/Anand

In the above example, the home directory is /home/Anand. To get back to your
home directory, you can simply type the change directory (cd) command.
$ cd

The UNIX system commands cd, ls, which work in the same way in L INUX
system.

110
5.2.5 Exiting the shell
To exit from the shell when you are done, you either type exit or press Ctrl+D. If
you are existing from your login shell (the shell that started when you first logged in),
type logout to exit the shell.

Exercise 2:

Practice the following:


1. What message will appear on the screen when the LINUX system on.
2. When you login into your account, which prompt appears.

3. Use pwd command to know your current directory.

4. Use cd .. command and then use pwd to know where you are.

5. Type echo $HOME command and then use pwd.

6. Type logout and see the effect.


7. Type exit from login mode and watch the difference with resp ect to
logout.

5.3 LINUX FILE SYSTEM

Objectives:
After completing this section, you will be able to:

• Know the hierarchy of LINUX file system


• Create your own directory
• Use ls command
• Use cd command
• Use chmod command
• Understand file permissions
• Move files from one directory to another directory

111
5.3.1 Working with the Red Hat Linux File system
The Red Hat Linux file system is the structure in which all the information on your
computer is stored. Files are organized within a hierarchy of directories. Each directory
can contain files, as well as other directories.
At the top is the root directory, which is rep resented by a single slash (/). Below that
is a set of common directories in the Linux system, such as /bin, /dev, /home, /lib, and
/tmp, to name a few. Each of those directories, as well as directories added to the root,
can contain subdirectories.
bin/ dev/ etc/
home/ ro ot/ tmp/ …

mary/
Anand/ tom/

memos/

briefs/ personal/
Figure 3-1 illustrates how the Linux file system is organized as a hierarchy.
Some of the Red Hat Linux directories that may be of interest to you include the
following:

• /bin- Contains common Linux user commands, such as ls, sort, date and
chmod.

• /dev- Contains files representing access points to devices on your systems.


These include terminal devices (tty*), floppy disks (fd*), hard disks (hd*),
RAM (ra m*), and CD-ROM (cd*). (Users normally access these devices
directly through the device flies.)

• /etc-Contains administrative configuration commands and files.

• /home-Contains directories assigned to each user with a login account.

• /mnt- Provides a locatio n for mounting devices, such as remote file systems
and removable devices (cdrom, floppy, and so on).

112
• /root-Represents the root user’s home directory.

• /sbin- Contains administrative commands and daemon processes.

• /tmp- Contain temporary files used by applications.

• /usr-Contains user documentation, games, graphical files (X11), libraries


(lib), and a variety of other user and administrative commands and files.
The files systems in the DOS or MS Windows operating systems differ from
Linux file structure.

5.3.2 Creating files and directories


You will use some of these commands in the file creation process:

• cd – Change to another current working directory.

• pwd – Print the name of the current working directory.

• mkdir – Create a directory

• chmod – Change the permission on a file or directory

• ls – List the contents of a directory.

The following procedure steps for creating directories within your home directory,
moving among your directories, and setting appropriate file permissions:

1. First, go to your home director y. To do this, simply type cd.

2. To make sure that you got to your home directory, type pwd. When
you do this, you get the following response (reflects your home
directory):

$ pwd
/home/Anand

3. Create a new directory called test by using mkdir command in your


home directory as follows:

$ mkdir test

4. Check the permission of the directory by typing:

113
$ ls - ld test
drwxr-xr-x 2 Anand sales 1024 January 24 12:17 test

Notice that this listing says that test is a directory (d), the owner is Aanand, the
group is sales, and the file was most recently modified on January 24 at 12:17 p.m.
Suppose that you want to prevent everyone else who uses this computer from using or
viewing the files in this directory. The permissio ns for the directory is rwxr-xr-x. The
coming section explains what these permissions are.

5. Type the following;

$ chmod 700 test

This command changes the permissions of the director y to give you complete access
and everyone else no access at all. (The new permissions should read like rwx --- ---).

6. Next, make the text directory your current directo ry as follows:

$ cd test

5.3.3 Understanding File Permissions


Permissions associated with files and directories in Linux (exactly similar to
UNIX) were designed to keep users from accessing other users’ private files and to
protect important system files.
The nine bits assigned to each file for permissions define the access that you and
others have to your file. Permission bits appear as rwxrwxrwx. The first three bits
apply to the owner’s permission, the next three apply to the owner’s group, and the
last three apply to all others.
You can see the permission for any file or director y b y typing the ls – ld name
command. The name file or directory will appear as those shown in the example below:

$ ls - ld ch3 test

-rw-rw-r-- 1 Anand sales 4983 Jan 18 22:13 ch3

drwxr-xr-x 2 Anand sales 1024 Jan 24 13:47 test

114
Here are some examples of how to change permission on a file and what the
resulting permission would be:

chmod 777 file names rwx rwx rwx

chmod 755 file names rwx r-x r-x

chmod 644 file names rw- r-- r—

chmod 000 file names --- --- ---

When you try to create a file, b y def ault it is given the permission: rw- r-- r--. A
directory is given the permission rwx r-x r-x. These default values are determined by
the value of umask. Type umask to see what your umask values. For example:

$ umask

022

5.3.4 Moving copying and deleting Files


Commands for moving, copying, and deleting files are fairly straight forward. To
Change the location of a file, use the mv command. To copy a file one location to
another, use the cp command. To remove a file, use the rm command. Here are some
examples:

$ mv abc def

$ mv abc ~

$ cp abc def
$ cp abc ~

$ rm abc

$ rm *

115
5.4 vi TEXT EDITOR

Objectives:
After completing this section, you will be able to:

• Open a file in vi editor


• Understand various vi commands
• Move around the file
• Search for text

5.4.0 Using the vi Text Editor


The vi editor is difficult to learn at first. But once you know it, you will be able to
edit and move around files quickly and efficiently. The vi in LINUX System is exactly
similar vi in UNIX system.

5.4.1 Starting with Vi


To open a file called /tmp/test, type the followin g command:

$ vi /tmp/test
If this is a new file, you should see something similar to the following:

116
~
~
~
~
“ /tmp/test” [New File]
To start out, type either of the following input commands:

a Add: After you type a you can input text that starts to the right o f the cur sor.

i Insert: After you typ e i you can input text that starts to the left of the cursor.

Type a few words and press Enter. Repeat that a few times until you have a few lines
of text. When you are done typing press Esc. Try moving around within that text with the
following commands:
Arrow keys Use the arrow keys to move up, down, left, or right in the file one
character at a time. To move left and right you can also use
Backspace and the spacebar, respectively. If you prefer to keep you
fingers on the keyboard, use h (left), I (right), j (down), or k (up)
to move the cursor.

w Moves the cursor to the beginning of the next word.

b Moves the cursor to the beginning of the previous word.

0 (Zero) Moves the cursor to the end of the current line.

$ Moves the cursor to the end of the current line.

H Moves the cursor to the upper-left corner of the screen (first line on
the screen).

M Moves the cursor to the first character of the middle line on the
screen.

L Moves the cursor to the lower-left corner of the screen (last line on
the screen).

Vi commands for deleting text:

x Deletes the character und er the cursor.

X Deletes the character directly before the cu rsor.

117
dw Deletes from the current character to the end o f the current word.

d$ Deletes from the current character to the end of the current line.

d0 Deletes from the previous character to the beginning of the current line.

Several ways of saving and quitting the file follow:

ZZ Save the current changes to the file and exit from vi.

:w Save the current file but continue editing.

:wq Same as ZZ.

:q Quit the current file. This works only if you don’t have any
unsaved changes.

:q! Quit the current file and DON’T save the changes you just made to
the file.

5.4.2 Moving around the file


Other ways o f moving around a vi file.
Ctrl + f Page ahead, one pages at a time.

Ctrl + b Pages back, one page at a time.

Ctrl + d Page ahead ½ page at a time

Ctrl + u Pages back ½ page at a time

G Go to the last line of the file.

1G Go to the first line of the file. (Instead of I, you could use any
number to go to that line number in the file.)

5.4.3 Searching for text


To search for the next occurrence of text in the file, use either the slash (/) or the
question mark (?) character. Within the search, you can also use metacharacters.
/ hello Searches forward fo r the word hello.

? goodbye Searches b ackwards for the word goodbye.

118
/ The * f oot Searches forward for a line that has the
word The in it and also,
after that at some point, the word
foot.

? [ pP]rint Searches backward for either the word p rint


or print. Remember
that case does matter in Linux, so
using brackets is one way to
search for words that could have
different capitalization:
The vi command was originally based
on the ex editor.
5.4.4 Using numbers with commands
You can precede most Vi commands with numbers
to have the command repeated
that number of times. Here are some examples:

3dw Deleting the next three words.

5cl Changes the next five letters


(i.e., removes the letters and goes
into input
mode).

12j Moves down 12 lines.

You might also like