0% found this document useful (0 votes)
323 views

Silicon Media Press Unix B01JCH3WOM

The document discusses the UNIX operating system and provides an overview of its history, characteristics, file system, utilities and commands. It covers topics like file permissions, editing files, communication tools, text editing and processing.

Uploaded by

Sammy Gapi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
323 views

Silicon Media Press Unix B01JCH3WOM

The document discusses the UNIX operating system and provides an overview of its history, characteristics, file system, utilities and commands. It covers topics like file permissions, editing files, communication tools, text editing and processing.

Uploaded by

Sammy Gapi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 217

Copyright 2001 - Silicon Media Press

All rights reserved. No part of this publication, may be reproduced or


distributed in any form or by any means, electronic, mechanical,
photocopying, recording or otherwise, or stored in a database or
retrieval system without the prior permission in writing of the
publisher.

Microsoft, MS, and MS-DOS are registered trademarks of Microsoft


Corporation. All other brand and product names are trademarks or
registered trademarks of their respective companies.
Every effort has been made to supply complete and accurate
information. Silicon Media Press does not guarantee the accuracy or
completeness of any information and assumes no responsibility for
its use.
First Edition 2001

I S B N - 8 1 - 8 7 8 7 0 - 09-5
The export rights of this book are vested solely with the publisher.
Published by Silicon Media Press, Regd. Off. I-19, Lajpat Nagar - II,
New Delhi. Works : KJ-75, Kavi Nagar, Ghaziabad. Ph - (0120)-914702867 [email protected] Typeset by : Ram Ganga Computers
(P) Ltd. and Printed by : Digisoft, D-30, Sector-6, Noida. Ph - 011891-4444598, 9810236378.

Dedicated to my parents,

who have always supported my decisions

Contents
UNDERSTANDING UNIX OPERATING SYSTEM ---------- 2
IMPORTANCE OF OPERATING SYSTEM ------------------ 2
FUNCTIONS OF O.S.------------------------------------------ 3
TYPES OF O.S. ------------------------------------------------ 3
INTRODUCTION TO UNIX------------------------------------ 4
HISTORY OF UNIX -------------------------------------------- 4
CHARACTERISTICS OF UNIX SYSTEM V ----------------- 6
INSIDE UNIX --------------------------------------------------- 8
Kernel .................................................................................... 9
CHARACTERISTICS OF UNIX FILE SYSTEM ----------- 11
Hierarchical Structure ......................................................... 11
Dynamic File Growth ......................................................... 11
Structure less files ............................................................... 11
Security ............................................................................... 11
Device independence .......................................................... 11
SYSTEM REQUIREMENTS --------------------------------- 11
User Login & Password ...................................................... 12
INITIAL PASSWORD ---------------------------------------- 13
SHELL GAMES ---------------------------------------------- 13
UNIX System Prompt ......................................................... 14
CHANGING PASSWORD ----------------------------------- 15
A brief session with UNIX ................................................. 16
FORMATS OF UNIX COMMANDS ------------------------ 17
Arguments to Commands ................................................... 18
Logging Out ........................................................................ 18
SHUTTING DOWN YOUR SYSTEM ----------------------- 18
SUMMARY ---------------------------------------------------- 20
EXERCISE ---------------------------------------------------- 22
THE FILE SYSTEM & GENERAL UTILITIES ------------- 24
THE UNIX FILE ............................................................... 24
Types of UNIX files ............................................................ 24
RULES FOR FILE NAMES AND DIRECTORY ----------- 27

PATH NAMES ------------------------------------------------ 28


CREATING A DIRECTORY --------------------------------- 28
CHANGING THE DIRECTORY ----------------------------- 29
REMOVING A DIRECTORY -------------------------------- 31
LISTING DIRECTORY CONTENTS ------------------------ 32
ls Command ........................................................................ 32
Group Command ................................................................. 37
CHANGING PERMISSION ---------------------------------- 37
chmod Command ................................................................ 37
DEFAULT PERMISSIONS ---------------------------------- 40
umask Command ................................................................ 40
Security and UNIX file System .......................................... 40
CREATING, DISPLAYING & CONCATENATING FILES - 41
cat Command ...................................................................... 41
LOOKING AT CONTENTS OF FILE ----------------------- 43
pg Command ....................................................................... 43
HALTED OUTPUT ------------------------------------------- 43
The more Command ........................................................... 43
FILE TYPES -------------------------------------------------- 44
The file Command .............................................................. 44
DISPLAYING A FILES CONTENTS ----------------------- 45
The od Command ................................................................ 45
COPYING FILES --------------------------------------------- 45
cp Command ....................................................................... 45
MOVING & RENAMING FILES ---------------------------- 47
mv Command ...................................................................... 47
REMOVING FILES ------------------------------------------- 48
rm Command ...................................................................... 48
Wildcards ............................................................................ 49
FINDING FILES ---------------------------------------------- 51
PRINTING A FILE -------------------------------------------- 52
lp Command ........................................................................ 53
lpr Command ...................................................................... 53
PRINTER STATUS INFORMATION ------------------------ 53
lpstat Command .................................................................. 53
CANCELLING REQUEST TO A LINE PRINTER ---------- 54
cancel Command ................................................................. 54
DISPLAYING A BLOWN-UP MESSAGE------------------- 54

The banner Command ........................................................ 54


SUMMARY ---------------------------------------------------- 55
EXERCISE ---------------------------------------------------- 57
UNIX TOOLS ------------------------------------------------- 60
FINDING TEXT PATTERNS IN A FILE(S) ----------------- 60
grep Command .................................................................... 60
egrep Command .................................................................. 62
fgrep Command .................................................................. 62
SORTING FILES --------------------------------------------- 62
Sort Command .................................................................... 62
SPLITTING A FILE APART ---------------------------------- 65
split Command .................................................................... 65
FILE COMPARISONS --------------------------------------- 65
comm Command ................................................................. 65
cmp & diff Command ......................................................... 66
dircmp Command ............................................................... 67
CUTTING FILES --------------------------------------------- 68
cut Command ...................................................................... 68
MERGING FILES -------------------------------------------- 69
paste Command ................................................................... 69
join Command..................................................................... 69
COUNTING THINGS IN A FILE ---------------------------- 71
wc Command ...................................................................... 71
CHECKING SPELLINGS ------------------------------------ 71
spell Command ................................................................... 71
VIEWING NON-ASCII FILES ------------------------------- 71
strings Command ................................................................ 71
SUMMARY ---------------------------------------------------- 73
EXERCISE ---------------------------------------------------- 74
STANDARD FILES ------------------------------------------- 76
REDIRECTING THE STANDARD OUTPUT --------------- 76
Appending standard output to a file .................................... 76
Redirecting the standard input ........................................... 77
PIPES ---------------------------------------------------------- 77
SUMMARY ---------------------------------------------------- 79

EXERCISE ---------------------------------------------------- 80
COMMUNICATION & ELECTRONIC MAIL --------------- 82
Sending messages to other user .......................................... 82
write Command ................................................................... 82
CONTROLLING MESSAGES ------------------------------- 83
mesg Command .................................................................. 83
THE PAPER-FILLED OFFICE ------------------------------ 83
SENDING MAIL ---------------------------------------------- 84
RECEIVING MAIL ------------------------------------------- 85
THE INTERNET ---------------------------------------------- 87
CREATING MAIL --------------------------------------------- 88
HANDLING MESSAGES ------------------------------------ 90
SAVING MESSAGES ---------------------------------------- 90
SUMMARY ---------------------------------------------------- 91
EXERCISE ---------------------------------------------------- 92
TEXT EDITOR VI & TEXT PROCESSING ---------------- 94
VI EDITING MODES ---------------------------------------- 94
Calling up VI Editor ........................................................... 94
MOVING WITHIN A FILE ----------------------------------- 95
Adding text to a file [Text Input Mode] ............................. 97
CHANGING TEXT-------------------------------------------- 97
Copying & Moving Text ..................................................... 98
Restoring and Repeating Changes ...................................... 98
SAVING CHANGES TO A FILE ---------------------------- 99
Editing a Second File .......................................................... 99
Finding out File Information............................................... 99
Interrupting & Ending vi editor .......................................... 99
Accessing UNIX Commands from within vi .................... 100
Text Processing ................................................................. 100
Useful troff Commands .................................................... 101
SUMMARY -------------------------------------------------- 103
EXERCISE -------------------------------------------------- 104
MULTITASKING -------------------------------------------- 106
Multiple Command, One System...................................... 106

REAL - TIME PROCESSES ------------------------------USING THE JOB SHELL --------------------------------SWAPPING AND PAGING -------------------------------SUMMARY --------------------------------------------------

108
108
109
111

ADVANCE NETWORKING TECHNIQUES -------------- 114


Reach Out & Touch Someone .......................................... 114
Informal Communication .................................................. 114
uucp Command ................................................................. 114
FREE SOFTWARE & FTP --------------------------------- 115
Using FTP ......................................................................... 116
What do I do with the file ? .............................................. 117
SURFING THE NET --------------------------------------- 117
The Usenet and Newsgroups ............................................ 117
READING & WRITING THE NEWS ---------------------- 119
Gophers - Information Organizers .................................... 120
THE WORLD WIDE WEB --------------------------------- 120
Page Limits ....................................................................... 120
Accessing the Web ............................................................ 121
SUMMARY -------------------------------------------------- 122
ADVANCED UNIX COMMANDS ------------------------- 124
awk Command .................................................................. 124
perl Command................................................................... 127
A First Perl Script ............................................................. 127
sed Command ................................................................... 128
at Command ...................................................................... 130
batch Command ................................................................ 130
cron Command .................................................................. 131
bc Command ..................................................................... 131
BACKING UP YOUR SYSTEM --------------------------- 131
tar Command..................................................................... 131
SUMMARY -------------------------------------------------- 134
GOING GRAPHICAL - THE X WINDOW SYSTEM ----- 136
The X Server ..................................................................... 137
Using X ............................................................................. 138

What X Looks Like ........................................................... 138


Using Startx ...................................................................... 140
Command- Line Parameters ............................................. 141
Using the Mouse ............................................................... 142
WINDOW FOCUS ------------------------------------------ 143
Working with Xterm ......................................................... 143
Starting Xterm................................................................... 144
LINUX- NEW GENERATION OPERATING SYSTEM -- 146
HISTORY OF LINUX --------------------------------------- 146
New Features .................................................................... 146
HOW IS LINUX DIFFERENT? ---------------------------- 147
What is a Linux distribution?............................................ 147
LINUX V/S OTHER OPERATING SYSTEMS ----------- 148
WHAT IS INCLUDED WITH LINUX? -------------------- 148
WHO USES LINUX? --------------------------------------- 150
INSTALLING LINUX --------------------------------------- 150
Disk partitioning ............................................................... 152
Installing Software Components ....................................... 152
Configuring Linux ............................................................ 153

Acknowledgments
We would like to thank all of the many people who helped bring this

book to print. Its really fascinating for us to write a book, because


what begins as a few thoughts ends up as a physical, tangible thing
that goes into the hands of many readers. The trip from thought to
thing is a long one and involves inputs from lots of people. Thanks
goes to all of our editors, art personnel and staff at Silicon Media.
Munishwar Gulati
I would especially want to thank my wife and co-author Mini Gulati,
who not only always cooperated and went through the whole book to

rectify me at many places, but also given lot of inputs about the latest
operating system - Linux.
Mini Gulati
It has been delight working with my husband and co-author Munishwar

Gulati. He persuaded me to write, what I knew and rectified it, to give

it a shape of chapter. My deep appreciation goes to him for his


constant enthusiasm and hard working.

About this book

As you read the book, you will find the answers to many of the
questions you have about UNIX.

How the book is organised


Chapter 1 introduces you to history of operating system UNIX, its
characteristics, and comparison with other operating systems. It also
tells you about the starting and shutting down UNIX OS.

Chapter 2 covers all about the file system of UNIX, creating, modifying
and deleting files and folders and various other associated commands.
As you move on to Chapter 3, you discover more about various UNIX
tools to play with files.

Chapter 4 covers all about redirecting output.


Chapter 5 tells you about communication in UNIX with other system
in the network.

Chapter 6 tells you about the text processing.


Chapter 7 gives you ideas about Multitasking in UNIX.
Chapter 8 tells you about Advance Networking Techniques used in
UNIX.

Chapter 9 tells you more about Advance Level UNIX commands.


Chapter 10
Windows.

introduces you to graphical interface of UNIX i.e. X-

Chapter 11 takes you to the introductory tour of LINUX - the next


generation Operating System

This book is a sincere effort for explaining the concepts of Programming

Language C. We sincerely hope that you find this work to be informative


and enjoyable.
Authors

Tell us what you think!

As a reader, you are the most important critic and commentator of

our books. We value your opinion and want to know what we are doing
right, what we could do better, what areas you would like to see us
publish in, and any other words of wisdom you are willing to pass.

As the publishing manager of the group that created this book, I


welcome your comments. You can e-mail at [email protected].

Chapter 1
INTRODUCTION
UNDERSTANDING UNIX OPERATING SYSTEM
IMPORTANCE OF OPERATING SYSTEM
FUNCTIONS OF O.S.
TYPES OF O.S.
INTRODUCTION TO UNIX
HISTORY OF UNIX
CHARACTERISTICS OF UNIX SYSTEM
CHARACTERISTICS OF UNIX FILE SYSTEM
SYSTEM REQUIREMENTS
FORMATS OF UNIX COMMANDS
SHUTTING DOWN YOUR SYSTEM

Chapter 1 : Introduction
A Computer is a collection of parts, some mechanical, some electrical
and some electronics. Getting all these parts to work together is a
major problem, and that is basically what an operating system does.
It manages, the resources of a Computer System and schedules its
operation. It provides a link between the user and the computer
hardware and software.
Operating system controls nearly every aspect of the computer
system. It transfers the control of computer to user and supplies the
way of communicating with the computer. Thus it provides the
interface between user and Computer. The principal functions of
operating system include :

To control and coordinate peripheral devices such as printers,


display screen and disk drives.
To monitor the use of machines resources.

To help the application programs and execute instructions.


To help the user to develop programs.

To deal with any faults that may occur in the computer and
inform the user/ operator.

The operating system is very important because it sets both the


environment in which you interact with the computer and the
environment in which your program work. Also the operating system
sets many of the practical limits of your computers usefulness, just
as the specific hardware does.

Also, the utility programs and other application programs will not
work with just any operating system and have to be generally
matched to the operating system. Thus, the number of packages
available for your computer is heavily influenced by the popularity of
operating system that it uses.
In many ways, it doesnt matter to us if our operating system is better
or worse than some other system. What does matter is how popular
our operating system is.

Computer system is just a collection of metal, silicon, communications


equipments and magnetic media. It is the application programs
which make a computer system useful to its users. Applications can
range from word processing, through writing compilers to generating
new operating systems.
To exploit the communications, data storage, and information
processing capabilities of the computer hardware, the application
software requires some form of overseer, which can handle the details
of managing the hardware resources, accessing the files and interacting

Chapter 1 : Introduction

with the users. These supervisory functions are the job of the
Operating System. Basically operating system is a manager of
resources and these resources include both computer hardware and
software. Operating system in a software which is made up by set of
programs and interprets users commands to the hardware and
decreases the distance between user and machine so that user can
work in a friendly environment. So operating system is a major part
of whole system and systems efficiency depends upon operating
systems efficiency

Check and management of one or several process.

Memory allocation

Input-output peripherals (keyboard, display, disks ,etc., )check


CPU time management.

There are different type of operating systems as per the requirements


of users. These are :

DOS
UNIX
OS/2
---------------

Every operating system has got its advantages and disadvantages. All
operating systems have more or less the same function, namely to
hold the ring between all the different hardware resources of a
computer in such a way that users can get their work done.

1)

Single Task

i)

the user request is converted into action (process).

iii)

all the computer resources are made available to the process.

i)

executes several processes simultaneously, on behalf of a


single user.

ii)

2)
ii)

3)
i)

ii)

one single process at a time.

Multi Task

computer resources are better operated, as they are shared


between all active tasks.

Multi user

multi task for several users.

resources shared between all the computer users.

Chapter 1 : Introduction
The UNIX revolution must be one of the finest things that has
happened to the computing industry in recent times. It has a large
number of outstanding and diverse concepts, developed and perfected
over a period of time. It simplified a lot of things and yet has
phenomenal power. It has practically everything an operating system
should have, and several features which operating systems never
had. Its richness and elegance go beyond the commands and tools
that constitute it, while simplicity permeates the entire system.
UNIX is a large computer operating system environment. It has a
large set of utility programs. These utilities include general user,
programm er, type setting, communication and administrative
commands. UNIX system is useful both for developing computer
software, and for producing documents. Both of these applications,
need many and varied tools for processing files of text and numbers,
and the UNIX system comes equipped with text manipulation tools,
documentation processing utilities, an electronic mail system, and a
flexible file system to hold everything together. The UNIX system has
introduced many new features to the computer world.

Back in 1960s, when computer development was the domain of a few


industrial leaders and leading universities. In this era much leadingedge research was being done at Bell Labs, MIT, and General electric.
The three had collaborated on an operating system called MULTICS
(Multiplexed Information & Computing System) for the GE 645
mainframe computer. MULTICS was not exactly a triumph and so it
met with a deserved death.
In 1969 Ken Thompson, a Bell Labs researcher and one of the
MULTICS developers, has written a MULTICS game called Space
Travel. In those days of time sharing, users had to pay for their time
spent on mainframe. It used to cost around $75 to play. So Thompson
& his colleague Dennis Ritchie rewrote the game to run on DEC PDP7 computer sitting unused at Bell Labs. But in order to transfer Space
Travel to DEC, Thompson had to write a new operating system for it
- the roots of todays UNIX.

The operating System was dubbed as UNICS (Uniplexed Information


and Computer System). Along the way it became UNIX and was ported
to more powerful computers. The first few versions of the UNIX system
were internal to Bell Laboratories. But in the early 1970s, Bell
Laboratories began distributing the system to universities. By 1972
there were exactly 10 computers running UNIX. Following year
Thompson and Ritchie rewrote UNIX in the C programming language,
a more portable language that helped established UNIX as an operating
system that could run on many type of computers. The result of that
move is that a whole generation of computer science graduates moved
into the industrial sector with knowledge of UNIX.

Chapter 1 : Introduction

During the period of 1974 and 1979, UNIX was really a research
product, becoming popular in universities for teaching purpose. The
UNIX of 1974 was different from UNIX of 1979. During the period
many utilities and tools were added to UNIX, while the computer
industry expanded rapidly, increasing the potential market for UNIX.
UNIX also became available on microcomputers in 1980, when
Microsoft released a scaled down version of UNIX called XENIX.
Microsoft is perhaps more famous for creating an alliance with IBM
that made its DOS (Disk Operating System) the most popular
microcomputer operating system. XENIX development was taken over
by Santa Cruz Operation ( a company partially owned by Microsoft),
and SCO UNIX is now an important product in UNIX world.

Until 1983, the UNIX system was confined mostly to university


computer science departments and to research institutions. It suffered
because it was not an officially supported product. In 1983, it
changed, when AT&T released UNIX system V Release 1 and promised
that software created for it would be compatible with all future
versions of UNIX from AT&T.
System V represents a point in an evolution of UNIX System. System
V retains most of the major characteristics of its predecessors. In the
course of UNIX development, a number of incompatibilities had crept
into the various versions, making uniform software development
somewhat difficult. And no matter how good may be the operating
system, if there are no useful application no one will buy and use the
operating system.
Thats why AT&T embarked on what it calls THE GRAND UNIFICATION
: UNIX System V Release 4. This newest version of UNIX combines the
most popular and most used commands from UNIX System V Release
3.2, BSD (Berkeley Software Distribution, responsible for many
common utilities such as text editor vi and C shell), SunOS (famous
for SOLARIS workstation) and XENIX.
UNIX is now owned by Novell, which acquired UNIX as a part of its
purchase of UNIX System Labs. However, UNIX transcends the
control of one corporation, as the UNIX industry works together to
determine standards.
Following are the evolutionary path for UNIX system i)

1969

ii)

1972

iii)

1979

iv)

1981

UNIX became a registered trade- mark of


BELL laboratories (AT&T)

The development of C - language makes it


possible to port this UNIX system on a
number of machines.
Development of UNIX BSD 3.0 (Berkeley
software Distribution)
UNIX AT&T SYSTEM III Release 1.0

v)

1982

vi)

1988

viii)

1990

vii)
ix)

1989
1990

Chapter 1 : Introduction

Creation of SUN C STANFORD University


Network) company and development of the
UNIX SunOS derived from the 4.1 BSD.
UNIX system V Release 3.2

Development of a standard UNIX referred


to as SVR4 (system V Release 4)
SunOS 4.1.1

UNIX SVR4 ON SUN station called SOLARIS


2.0.

UNIX has a number of features, mostly good & some bad, but it is
necessary to know atleast some of them. It is indeed unique, a
product of several talented people who combined many ideas and cast
them in a simple and easy-to-understand structure.

Interactivity

System V is an interactive operating system means system obeys the


commands typed by user and displays responses.

Multitasking

System V is a multi- tasking operating system means system can


perform several tasks - called processes - at the same time. A user can
run several commands in background while executing another
command in foreground. Background refers to the commands that
are detached from your terminal. Foreground is the execution of a
command attached to your terminal. UNIX can be configured to allow
the user to run from one to as many processes as the operating
system can handle.

Multiuser

System V is a multiuser operating system. This means that more than


one person can use the system at the same time. The multiuser aspect
comes as a natural consequence of the multitasking feature : the
system can attend to more than one user at a time just as easily as
it can do more than one job at a time for one user. A single user cannot
use the printer, disk, memory, or cup 100 percent of the time. But
multiple users can increase use of these devices and resources by
having an operating system that manages the resources for them.
This reduces the cost as per user of the computer as more users share
the system. UNIX currently runs on systems that support from one to
over 2000 users.
The concept of a multiuser system is to approach 100 percent in
computer resource utilization while reducing the cost per user.

Chapter 1 : Introduction

Portability

UNIX introduced the idea of moving an entire operating system.


UNIX is highly portable. Portability is the ability to rewrite the
operating system for a different vendors hardware without a major
rewrite effort. Till UNIX appeared on the scene, operating systems
were written in assembly language, which used less memory, and
executed instructions faster than those written in other languages.
UNIX exploded the notion that machine efficiency was more important
than human productivity. Most operating systems are written for one
specific machine or architecture and this makes it difficult to port
these operating systems to a different vendors computer. But UNIX
is highly portable as it has been written in C language and so
provides a standard application development environment that allows
for easy porting of application software. Portability allows the customer
to choose the computer and not to be locked into hardware and
software environment. It also provides the user with a broad base of
application software that can be used on different hardware.

Built-in networking

Today one of computings biggest challenge is to link different types


of computers across small and large areas. With UNIX, the networking
is built in with various programs and utilities.

The Featureless File

Apart from the illusory effect that the system produces of a file having
absolute coordinates, UNIX doesn't really care to know the type of file
that you are using. All files are alike in the UNIX system and it
considers even directories as devices of the file system. A file to UNIX
is simply an array of bytes, and its size is simply equal to the number
of bytes that you put into it. It can contain virtually anything; text,
object code or a directory structure.

Pattern Matching

The system was designed to see that a minimum number of keystrokes


achieve the maximum amount of work. That is why UNIX commands
are seldom more than four characters long. But it is the pattern
matching feature of UNIX that makes it so attractive to the
programmer. You listed of specifying all the file names explicitly.
The * is a special character used by the system to indicate that the
expression can match a number of file names. If you choose your file
names carefully, then you can use a simple expression to access a
whole lot of them.

Open Systems

The system from the very beginning had on open architectureone


could add to the tool kit by simply writing a program and storing the
executable in a separate are in the file system. A separate device can
also be added by creating a file for it. This is possible because
everything in UNIX is treated as a file; whether it is a source program,

Chapter 1 : Introduction

an executable, a floppy device, printer or terminal. Modification of


the system is easy because the source code is always available.
Moreover, with the vast amount of information available on the
subject in the form of books magazines, courses, etc., UNIX can be
used more efficiently.

Programming Facility

UNIX is highly programmable ; it was designed for a programmer, not


a causal end user. To appreciate and exploit UNIX fully, one must
be a programmer. An MS-DOS user who is not a programmer will
certainly find the transition quite overwhelming.

The UNIX shell has all the necessary ingredients like control
structures, loops and variables which establish it as a programming
language in its own right. Though the language is somewhat difficult
to learn, it has phenomenal power. The shell programming language
simplifies a number of things which are simply impossible to conceive
in other languages. It can be combined easily with the commands
and other programs in such ways that it may sometimes appear that
the two are inseparable. Proficient UNIX programmers seldom take
recourse to any other language for text manipulation problems.

UNIX is an operating system in the same way MS-DOS and OS/2 are
operating systems: software that controls the physical computer and
interprets your commands.
An operating system performs many functions :

It actually runs a program. When a programs file name is


entered at the command line, the operating system takes over
by loading the program into the computers memory and runs
it. Adjustment in the operating system can affect the actual
performance of the programs.
It controls all input and output on the computer. When a
file is deleted, the operating system goes ahead and eliminates
a record of that file. When a file is saved, operating system
makes sure that the file is not written over an existing file. The
operating system also controls the display and allows to input
commands with a keyboard & a mouse.

UNIX carries out these functions through three separate, but closely
integrated parts: the file system, the shell and the kernel.

kernel

file system

shell

Two of these parts - the file system and the shell are visible to the
users. The other major part - the kernel is not really visible.

Chapter 1 : Introduction

The entire UNIX system is supported by a handful of essentially


simple concepts. Foremost amongst them is the division of labour
between two agencies, one interacting with the user, and the other
with the machine's hardware. This is achieved by two abstract
constituents - the kernel & the shell. The relationship between two is
depicted below.

KERNEL

UNIX kernel is the main operating system program. It controls and


manages the computer system and the peripherals that are attached
which includes disks, tapes, printers, terminals, communication
lines, and any other devices. UNIX kernel has been written in C and
assembly language program that provides the low level functions of
the UNIX environment .It controls the system resources, allocates
time between users & processes, decides process priorities, provides
an interface for all other UNIX programs to use the hardware and
performs all other tasks which you wouldn't like to bother about. This
concept allows the higher level programs to be hardware independent,
and makes UNIX system highly portable . When UNIX is ported to
an oth er ha r d wa re p la tfo rm , on ly th e k e rn el re q uir es m a j or
modifications. Since most of the UNIX software interfaces with the
kernel and not the hardware, the software is hardware independent
and does not require much modifications.

10

Shell

Chapter 1 : Introduction

Shell is a very powerful and dynamic UNIX utility that functions as


the UNIX command interpreter. Shell is an interface between the user
and the kernel. The shell translates users request into a set of
instructions and communicates them to the kernel. The shell is a
command language and a programming language. As a command
language it can be used to communicate interactively with the kernel.
As a programming language users can write shell scripts to solve
simple and complex problems.
Shell is a program that runs automatically when you log in to system
V. It reads each command typed by user at terminal, and interprets
all commands and for that it calls up the program from the appropriate
place, then passes all the arguments to that program and starts it up
So shell forms the interface between users and the rest of the system.

There are several popular shell in existence. These are C shell, bourne
shell and the korn shell (ksh). If UNIX display a $ prompt it is bourne
shell; if UNIX display a % , it is C shell .These days, because all
versions of UNIX come with both shells, users can select the shell
which they want to use.
Bourne shell

It has been named after Steve Bourne, who originally wrote it. Bourne
shell is a program and its program name is sh means it can be called
by command Sh. UNIX display $ prompt for this shell. There are flew
other versions of original Bourne shell, most notably the Bourne
Again shell ( also called bash).
Korn Shell

The korn shell (ksh) is an enhanced version of the Bourne Shell (sh).
The ksh is a sophisticated command interpreter but basically the
korn shell is same as the Bourne shell.
C Shell

C Shell has been written by one of the BSDs architects Bill. The C
shalls program name is csh. The most notable difference between the
C shell and other leading shell is that the C shell has many more
magic characters.

File System

File system is the organizing structure for data in which data is stored
in files. The organization of system Vs file system is a hierarchical file
system which resembles a tree and so sometimes it is called a tree
structured file system. The UNIX file system supports two main
objects- files with a special format, so the representation of a file is
the basic UNIX concept. Directory actually contains list of file names
so that files can be found in the file system. UNIX file system has a
root directory which is at the top of tree. This root directory can have
many sub-directories which in turn can have more sub-directories

Chapter 1 : Introduction

11

and so on. The details of the file system has been discussed in the
Unit-3.

HIERARCHICAL STRUCTURE

This UNIX file system structure is referred as a tree structure and so


it starts with one master directory called root directory. This
structure allows maximum flexibility for storing information and
allows grouping of related information and efficient manipulation of
these groups.

DYNAMIC FILE GROWTH

Files grow as needed, no advanced decisions have to be made about


file size. Disk space is not wasted, since only the amount required to
store the current contents of file is used.

STRUCTURE LESS FILES

There is no internal structure imposed on contents of file and files are


treated as stream of bytes.

SECURITY

Unauthorized users can be restricted from accessing a file.

DEVICE INDEPENDENCE

Input and output from a device is processed as if it were in a file.


Therefore, programs that process data in a file can also process data
to and from a device.

The UNIX system has been ported to every major hardware vendors
machine. With over 150 designs of computers running UNIX, ranging
from micros to supercomputers, there exist differences between
various UNIX implementations. As UNIX is a multiuser, multitasking
system, it is hard to know each system requirements. Below given is
a general guideline what a user will need before starting to work on
computer.

An account on the UNIX system; provides you with a user


name.
An ASCII terminal

A direct line to the computer from the terminal

The above guideline is for multiuser system. In multiuser system the


actual computer may be located in your office, in another room, in
another building or even in another country.

12

Chapter 1 : Introduction

If a single-user system is being used, it will have a standard keyboard


and a monitor that is attached directly to the computer. A Sun SPARC
station, SCO Open Desktop, or Linux user falls into this category.

USER LOGIN & PASSWORD

Every user who uses UNIX is given a special User login or user name
to identify the user. This login is assigned by the superuser. Super
user is the administrator of whole system and assigns new user
names and so looks after whole system. The super user of system has
the name root as user name.

To gain access to UNIX system every user has to login to the system.
This process is called loging in. To login to system, user name is to
be typed and then carriage return key is pressed.

In addition to user name, every user has a password but this


password is users own choice and even superuser cannot figure out
what it is.
So to have access on UNIX system, this information is to be given

login : smedia
password :

As password is typed, it is not displayed on the screen because it is


private to the user and nobody else can see while you are typing it on
system.
User login should be typed in lowercase letters as System V
distinguishes between upper and lowercase letters. If user login is
typed in capital letters then system might not recognize you as a valid
user and login incorrect, message will be displayed.
The above elements are common to virtually every UNIX-based system.
Depending on the UNIX vendor, you may see slight variation of
information displayed on the terminal.
SCO UNIX

Welcome to SCO System V/386


systemid!login : smedia
Password:
Welcome to SCO System V/386
From
The Santa Cruz Operation, Inc.

UNIX System V Release 4

login : smedia
Password:
UNIX System V Release 4.0 AT&T 3B2
systemid

Chapter 1 : Introduction

Copyright (c) 1984, 1986, 1987, 1988 AT&T


All Rights Reserved
Last login : Fri Jun 8 10:45:21 on term/12

13

Sun SPARC station

systemid login : smedia


Password:
last login: Fri Jun 8 10:45:21 from nokomis
Sun OS Relea se 4.1.1 (GEN E RIC) #1: Thu Oct 1 1 10: 25:14
PDT 1990

Depending on the UNIX installation, you might or might not have a


password already assigned to you when you first log on the system.
Sometimes no password is assigned and user can set his own
password with Passwd command and if user wants, he can work
without password also. This may also happen that superuser,
assigns passwords to users and then later on users can change their
passwords by using passwd command.

When you login the UNIX system, youre immediately thrust into the
login shell. All the information about the shell, as well as other login
information is contained in the file /etc/passwd, as is login information
for all your user on the system.

Every aspect of the UNIX is controlled by a shell of some sort. A shell


is a program that virtually controls all the processing of UNIX
commands. It behaves as the intermediary between you and the UNIX
system. In other words, it translates all the instruction in such a way
that UNIX system could handle those instructions.
UNIX features several shell. For most of the part you would like to
stick the shell chosen by your system administrator, since that allows
certain level of conformity among users. Single user has the freedom
in that respect to use any of the available shell. The major shell
include:

sh k sh cshjs hbashwksh-

pdksh-

The Bourne shell


The korn shell
The C shell
The job shell
The Bourne Again shell
The windowing Korn shell

The public domain Korn shell

14

Chapter 1 : Introduction

UNIX SYSTEM PROMPT

After user gives user login and password to the system a system
prompt is displayed. Generally this system prompt is $.This prompt
tell the user that UNIX system is waiting for user to type a command.
Every time the system has finished running a command and waits for
further action, it replies with the $ prompt.
At the end of every line or every command which is typed in front of
$ user has to press carriage return key and only when this key in
pressed system is able to see input given by user.
It is also possible that after giving user login and password, system
can display login messages and after that it will display the $ prompt.
This login messages are usually information about system, maybe
some added features etc.
If you are the root user on the UNIX system, the prompt will be

To find out the shell being used by you,

$ echo $shell
sh

The shells are stored in the /usr/bin directory on a UNIX system. To


find out all the available shells:

$ ls /usr/bin/*sh
/use/bin/csh

/usr/bin/ksh

/usr/bin/sh

You may want to change your prompt to appear more like the DOS
prompt. In this case you would enter the following command:

$ PSI = >

String $ to the string >, with a space at the end. The space is so that
the command you type, should not be with the prompt. The quotation
marks wont appear on the screen; only the characters between them
will appear. You can run the PSI command whenever you want it It
affects only your account, so you can personalize the string to
whatever extent tickles your fancy. For instance if you have a task to
perform at a specific time in the day, you could run a command like
the following

PS1 = Call Dr. Johnson at 3 >

Your prompt would be:

Call Dr. Johnson at 3 >

Chapter 1 : Introduction

15

If you are logging on an account set up by system administrator, you


may have to enter a new password to replace the original password
provided by the system administrator.

The password can be changed by passwd command. The process is


simple, after logging in onto the system, run the command passwd
and the system confirms the old password and asks for the new
password. This process look like following:

$ passwd
changing password for smedia
Enter old password:
Enter new password:
Retype new password:
Password changed

Some UNIX system may even force to choose a new password every so
often - the official UNIX terminology is that passwords age and so
must be replaced. The system administrator can set the password
time limits. In the Rel 4 the status of the password can be displayed
by adding -s command-line parameter to the passwd command.

$ passwd -s
smedia
PW
name
passwd status

06/15/96

10

40

date last changed


min days between changes
max days between changes
days before user will be warned to change password

The final six status line directly relate to the second line which has
six answers respectively.

Security Tip

Since security is so important to so many UNIX system, there are


variety of tools that enhances security while not impacting too heavily
on users.

One such tools is the lock command, which is found in many but not
all versions of UNIX. The lock command locks the keyboard unless
password is entered.

$ lock
Password:

16

Chapter 1 : Introduction

Sorry
Password:

If correct password is not entered, then the lock command fails to


release control of the keyboard. If the correct password is not entered
in a certain number of tries, then the lock command logs you off of
the system automatically.

A BRIEF SESSION WITH UNIX


cal

This displays a one month calender:

$ cal
S
7
14
21
28

January 2001
M
T
W
1
2
3
8
15
22
29

9
16
23
30

10
17
24
31

09:19:50

pst

T
4

11
18
25

F
5

12
19
26

S
6

13
20
27

If the calender for the entire year is required type :

date

$ cal 2001
$ date

wed Apr 4
$

1996

Word date is typed and a carriage return is pressed. The system


displays the current date 4th April, day as Wednesday, time as
9:19:50 and year as 1996. This is the default display and we can also
set the format of date and time the way we want.

who

$ who
sally
smedia
mack
$

term/10Apr 4
term/07Apr 4
term/06Apr 4

9:00
9:15
9:17

This command who tells you who is using the system. The information
displayed is - user login name, systems name for the terminal they
are logged on at, and the time they logged on.

Chapter 1 : Introduction

who am i

$ who
mack
$

am i
tt3

17

Apr 4

9:17

Here instead of previous command who, who am i is typed and it


displays the information about the user on the terminal, on which
this command has been typed. Here the first word is who only and
remaining words am i are arguments to command.

finger

In a larger systems, the detailed list of users can be displayed than


the one used in our who example. To get more information about
specific users, use the finger command:

$ finger smedia

This gives more information about smedias identity:

Login name : smedia

In real life : John F. Kennedy

(234) 555-2333
Directory : /usr/user
Shell : /usr/bin/ksh
Last login Fri Jun 11 12:12:34 on term/07
Project : C programming
smedia
term/07Jun 12 14:23

Using the finger command with an argument provides information


about the user, no matter whether they are logged to the system. If the
detailed information about everyone currently logged onto the system,
type:

$ finger

A command is the name of a program or utility followed by options


and arguments used by program. The command interpreter shell
reads input from terminal, interprets what has been typed, and
attempts to execute a program based on the input. The program
called is a file that contains executable code. There are certain
commands in UNIX for which shell does not require to call other
programs and interprets them by itself.
General format of a command is a sequence of words, each word being
separated from its neighbours by one or more spaces (blanks) .The
entire commands is terminated by a newline character, which is
produced on pressing RETURN key .The first word is the command
itself. The remaining words are arguments to the command.

18

ARGUMENTS TO COMMANDS

Chapter 1 : Introduction

There can be three types of arguments to commands 1.

Filename

2.

Option

3.

expression

the name of a file which the command is to


manipulate in some way.

this is a literal generally introduced by a


minus ( -) sign ( ex - -a, -l, etc.) An option
modifies the action of the command in
some way, or gives details of exactly now
the command is to operate.
an expression describing a character using
which is to be used as inpu t to the
command. I n the sim plest case the
expression is the string itself.

So general command format will be having a order like this.

Ex.

Command

option

1 ) ls -al

expression

filename (s)

This is a command l to display files and uses option - al to


display some particular information in different manner.

2 ) rm old.pat new.pat

This is a command rm to remove two file names called old. pat


and new.pat

LOGGING OUT

When youre ready to leave the terminal - its good idea to log off the
system. Why? Security, mainly. If you leave your terminal and are
still logged in, some one else could come in and tamper your
information.
To log off the system, type:

$ exit

login:

If you are bash or ksh user. If youre a C shell user, exit will work or
you can type:

% logout

These command should work on virtually every UNIX system. If they


dont work in your situation, try one of the following

logoff
bye

Because it takes so long to boot a UNIX machine, most are left on 24


hours a day, seven days a week, with only the monitors or terminals

Chapter 1 : Introduction

19

turned off. However, there are times when you want to turn off your
system. Earlier we mentioned the shutdown state of 0. A better way
of shutting down your system is through the command shutdown. If
used correctly, shutdown will shutdown the system and alter other
users that the system is shutting down:

# shutdown

If for some reason you get an error message when you run these
commands, you may want to try specifying the full path name of the
commands. On older systems, the command line is:

# /etc/shutdown

On SVR4 systems the command line is :

# /usr/etc/shutdown

After using the shutdown command the system will ask you if you
want to send a message before shutting down, and how long to wait
before shutting down. It will also confirm that you really want to shut
the system down. If youre working by yourself on a UNIX workstation,
you can send a message to them, and you can give them 60 seconds
before shutting down.
With System V UNIX you can speed up the shutdown command using
the following command line parameters:

# shutdown -g0

-y

The -g option specifies the grace period before shutting down, in


seconds. The zero(0) means that we dont want to wait at all. The -y
answers yes to the question do we really want to shut down. Thus you
wont be prompted to confirm the shutdown operation.
After shutdown runs, it display something like the following:

Safe to Power off


-orPress Any Key to Report

or
Reboot the computer now.

20

Chapter 1 : Introduction

The Operating System is used for the supervisory functions,


which includes to exploit the communications, data storage,
and information processing capabilities of the computer
hardware, the application software requires some form of
overseer, which can handle the details of managing the
hardware resources, accessing the files and interacting with
the users.
The major function of O.S. are
i.

to check and management of one or several process.

iii.

Memory allocation

ii.

iv

Input-output peripherals (keyboard, display, disks


etc. )check
CPU time management.

UNIX is a large computer operating system having the ability


of multitasking & multiprocessing. It has a large set of utility
programs. The main characteristic of UNIX operating system
are :

Interactivity - system obeys the commands typed by user


and displays responses.
Multitasking - system can perform several tasks - called
processes - at the same time. A user can run several commands
i n b a c k g r o un d wh i l e e x ec ut i ng a n ot h e r c o m m a n d i n
foreground.

Multiuser - means that more than one person can use the
system at the same time. The multiuser aspect comes as a
natural consequence of the multitasking feature : the system
can attend to more than one user at a time just as easily as it
can do more than the job at a time for one user.
Portability - Portability is the ability to rewrite the operating
system for a different vendors hardware without a major
rewrite effort
Built-in-network - is to link different types of computers
across small and large areas.
An operating system performs the following functions:
-

It actually runs a program.

It controls all input & output on the computer.

UNIX carries out these functions through three separate, but


closely integrated parts :
Kernel - It controls and manages the computer system and
peripherals that are attached to the system.

Shell - It is an interface between the user and the kernel. The


shell available in UNIX are:
Bourne shell
Korn shell
C shell

Chapter 1 : Introduction

21

File System - is the organizing structure for data in which


data is stored in files. The UNIX file system has following
characteristics:
Hierarchical structure
Dynamic file growth
Structureless files
Security

Device Independence

Every user on a UNIX system has an account. You start


computing in your account by logging in. To do so, you enter
your user name (or account name) and a password to
authenticate that you are really you.
Guard your UNIX password with your life. It is the key that
unlocks all the information in your account. Choose a password
carefully and dont write it down by your terminal. Change
your password with passwd command.
Dont forget your password or youll embarrass yourself in
front of your system administrator.
You can lock the password using lock command, when you
leave the terminal for short time.
cal

command displays calender of the month.

who

co m m a n d di sp la ys t he u se r n a m e &
terminal address of those who are using
the system at that time.

date

who am i
finger

command displays the current date.

command provides the detailed information


about the user on the terminal.
command gives the more detailed
information about the specific user.

The general format of UNIX command is

To log out from the terminal type

To completely shut down the system type

command
$ exit

$ shutdown

option

expression

filename(s)

22

Chapter 1 : Introduction
1.

What is the basic philosophy of the UNIX Operating System?

3.

What does multiuser mean?

2.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
a)

b)

What does multitasking mean?

What are four characteristics of the UNIX file system?

What are the three types of files used in a UNIX file system?
What two functions does the shell perform?

How the kernel is an important part of a UNIX operating


system.
What is the difference between UNICS & UNIX?

How many types of UNIX operating system are there in the


market?
What is the significance of a password in a UNIX system?

Write down the command to display the present working


shell. Who has more freedom in working on different shells Single user or Multiuser & why?
Explain password aging.

What the reasons for using the passwd command?


What does the cal command produce?

What does the command cal 99 produce?

Can you (a normal user) change the system date?


Explain the format of UNIX commands.

What is the command to change the command prompt? How


will you change the prompt to Siliconmedia>
State True or False:

lock command will permanently lock the UNIX system.

System administrator has access to password of all users.

c)

SCO UNIX & UNIX SVR4 are the same.

e)

who command displays all the users, irrespective of the fact


whether they are working or not.

d)
f)

date command doesnt display the year.

finger command displays the information about one user at


a time.

Chapter 2
UNIX FILE SYSTEM
THE FILE SYSTEM & GENERAL UTILITIES
THE UNIX FILE
RULES FOR FILE NAMES AND DIRECTORY
PATH NAMES
CREATING A DIRECTORY
CHANGING THE DIRECTORY
REMOVING A DIRECTORY
VARIOUS COMMANDS

24

Chapter 2 : Unix File System


Every thing in UNIX operating system can be represented by a file. A
letter you write, a program, computer, monitor, harddisk - all of these
physical entities can be represented by the abstract file.

Simply speaking, a file is a computer structure to store information.


This information is stored in the electronic format that a computer
can use - in bits. A bit is either 0 or 1; when strung together, these
bits comprises the characters that are recognizable. There are 8 bits
in a byte, 1,024 bytes in a kilobyte and so on.... Of course it is not
required to keep track of all 1,048,576 bytes in the one megabyte
document - thats what UNIX is for.

THE UNIX FILE

A UNIX file is a storehouse of information . It is simpy a sequence of


characters, UNIX places no restriction on the structure of a file and
you dont need to assume a predefined structure to work with it. A
file contains exactly those bytes that you put into it, whether it
represents a source program, other text or executable code. A file
neither contains its size nor its attributes. It doesnt even contain the
end of file mark. All file attributes are kept in a separate location in
the disk specially marked for this purpose. When a file is called up
by a command or program, it is this area that is looked up first before
the contents are accessed.
Every file has a file name. A filename is upto 14 characters in length(
Release 4). Other versions of UNIX, such as BSD, allows for much
longer filenames - as many as 256 characters.

TYPES OF UNIX FILES

Basically UNIX knows about three kinds of files.

Ordinary files

Device files

Directories

Ordinary Files

Ordinary files are used to store data. It is like a container in which


data is put and a name is assigned to this container by which it is
referred. By using this name, any command works on the whole
collection of data in the container.
The contents of a file can be displayed, files can be copied, they can
be removed from file system, or they can be moved around in the file
system.

Data can be stored in any format in ordinary file. The UNIX system
views files as a stream of bytes, it reads and writes them byte by byte
or block by block, not interpreting the data and so kernel does not
impose a structure on files.

Chapter 2 : Unix File System

25

A file in UNIX is represented by an inode (index node). An inode is a


record that stores most of the information about a specific file on the
disk. The inode contains

User and group identifiers of the file.

A count of number of hard links (directory entries) to the file.

Directory

Time of last modification and last access of file.

Type of file (plain file, directory symbolic link, character


device, block device etc.)

A directory is a storage area where any combination of files and subdirectories can be managed. Directory contents are kept in data
blocks and directories are represented by an inode in the same way
as plain files. Only inode type field distinguishes between plain files
and directories. Plain files are not assumed to have a structure,
however, while directories have a specific structure.
The first two names in every directory are , and ... New directory
entries are added to the directory in the first space available, generally
after the existing files. The file name . in a directory is a hard link
to current directory itself. The file name .. is a hard link to the
parent directory. Thus if the current directory is /user/bin/programs,
then ../bin/wdf refers to /user/bin/bin/wdf means the path is
directed towards parent directory bin.

Directories are themselves files - A path name to a file is a text string


that identifies a file by specifying a path through the directory
structure to the file. So the user refers to a file by a path name, while
the file system uses the inode as its definition of a file. Thus the kernel
has to map the users pathname to an inode and directories are used
for this mapping.
First a starting directory is pathname is /, the starting directory is
the root other than a /, the starting directory is the current directory
of the current process. First one which starts with / is called
absolute pathname and other one is called relative pathname.

e.g.

/usr/local/font in the example of absolute pathname. First


slash ( /) indicates the root of the directory tree, called the
root directory. The next usr is a sub-directory of root, local is
a sub-directory of usr and font is a file or sub- directory in the
directory local.
Local/font is the example of relative path name and indicates
a file or directory named font in the directory local in the
current directory which might or might not be/usr.
if current path is

/ export/home/gaston

then absolute path is

/export/home/gaston/source

and relative path is

source/manager.C

26

Chapter 2 : Unix File System

/manager.C

If current path is

/export/home/gaston

then absolute path is

/export/home/arthur/source/
Cege.C

and relative path is

/arthur/source/c ege.C

So in brief we can say about directories

Directories are specific files used as nodes in tree structure.


They comprise any files or sub-directories

By default there is no limit of their size C No. of files they


contain.
They always contain of two files
.

..

- Reference to directory itself

- Reference to parent directory.

A root directory is a specific directory, it is its own parent, .


and .. point to root. The main and compulsory directories are
as followsroot

root of the tree structure symbolized by /.

etc

etc.. all that the files referring to machine


administration

bin

tmp

home

dev

usr

lib

lost + found -

Device File

command binaries ( link on/usr/bin)


keeps temporary files.

files that have lost their names and have


been restored are kept here so, there is one
lost+found directory per file system.

working directory of users (When logged


in, the system immediately place you in
the home directory)
special files corresponding to
peripherals ( device special files).

the

A directory for each user ID recognized by


system.

library files such as C, pascal and Fortran


library subroutines are kept in lib.

The definition of a file has been broadened by UNIX to consider even


physical devices as files. This definition includes printers, tapes,
floppy dives, hard disks and terminals. Although this may appear
confusing initially, it is really an advantage; you dont need any
special command or function to use such a file. The device file is
special in the sense that any output directed to it will be reflected
on to the respective I/O (input/output) device associated with the
filename. Thus, when you issue a command to print a file, you are
really directing the files output to the file associated with the printer.
When you back up files onto tape, you are symbolically using the file

Chapter 2 : Unix File System

27

associated with the tape drive. The kernel takes care of this by
mapping special filenames to their respective devices.

UNIX distinguishes between upper and lower case letters, so


we can have two files with same name but one in upper case
and other in lower case letters means - local and LOCAL will
be two different files.
In older versions the limit was 14 characters for a file name.
But in newer versions it can consist of at most 256 characters.

Flenames can consist of any characters but many characters


but many characters in ASCII character set can mean
something special to SHELL (part of system that decodes
commands) and so these special characters - ; , >, <, 1, &
which mean something special to the shell, must be avoided.
When choosing name for file, it is best to choose name
consisting of letters, digits and underscore character ( -) and
the period character) (.) The period can be used safely in the
middle of a file name but it should not be used at the
beginning of a file name unless you want the files hidden.
UNIX command must be avoided to be used as file names.

Naming Convention

Certain naming conventions are followed on UNIX for various


programming languages available.

A file name ending in C is taken to be a file of C programming


language. A file name ending in .f is taken to be a program written in
FORTRAN, one ending in P is assumed to be a pascal program and a
filename ending in .s means a program written in assembly language
object code files produced by compilers are usually named with the
file name ending in .O. There are certain other conventions related
with other types of files but these are file naming conventions just to
avoid confusion among different type of files and not the rules
imposed by system. Some commands, that deal with certain type of
files; expect the names of those files to have a particular format; but
the shell and the system in general, doesnt care.

Printing Current Working Directory

pwd command displays the pathname of working directory.

$ pwd
/users/home/smedia
$

This command displays the current directory as/ home/smedia. Here


all directories are separated by a /(slash). The root directory is
represented by the first/, and the last directory named is your
current directory or current working directory.

28

Chapter 2 : Unix File System

The name of the directory displayed by pwd command, is the full


pathname to your directory, which specifies the whole relation of this
directory to the total file system.
You can create files, make sub-directories, remove files, or rename
files and directories under your present directory as you must have
been given permissions for these operations by system administrators.

As described earlier, the two files cant have same name and case.
Either the lettercase of the files must be different or the names must
be different. However, you can create the files of the same name if the
files are located in different directories. These different files, but with
the same file name in same case are distinguished by their pathnames.
For example consider two files Calc.report in two directories home &
smedia

/home/Calc.report

and

/home/smedia/Calc.report

These are called full path names because they provide an exact
description of the files location in the directory structure. Here the
initial slash (/) refers to the foot directory.
The following slashes separate the names of sub-directories within
sub-directories. The final slash denotes the actual file name.

mkdir Command

This command creates one or more new directories. Each new directory
contains the standard entries: .(dot) and .. (dot-dot).

mkdir

test

mkdir jet met

This command will create a new directory called test in current


working directory.
This will create two new directories called jet and met in current
working directory.
To have a look on created sub-directories, type the following command.

$ ls
jet
$

met

test

Chapter 2 : Unix File System

29

Information displayed are the name of directories which have been


created. ls is the command to display the contents of directory.
(Discussed in the next section).
Now the directory structure is like this -

/
home
smedia
test

met

mack

sally

jet

Here / represents the root file system which has a users subdirectory named home under which there are 3 sub directories for 3
users - smedia, mack and sally. And user smedia has created three
sub-directories in the smedia directory.
When a new directory is created, the system builds a new inode
(information node) for the system builds a new inode (information
node) for the directory. This allows access to the data stored in the
directory file and informs the system that the file is a directory type
file.

cd Command

This command changes the present working directory.

$ cd test

This command will change the current directory to test and now if you
type pwd command

$ pwd
/home/smedia/test
$

Now whatever operations will be performed, will be carried out on test


directory.

$ mkdir pass fail

This will create two sub-directories pass and fail of directory test and
now directory structure will be like shown below.

30

Chapter 2 : Unix File System

home
smedia
test
pass

met

mack

sally

jet

fail

$ cd pass

This will make your present working directory as pass and now if you
type pwd.

$ pwd
/home/smedia/test/pass

So basically when cd command is used with specific directory name,


it goes down one level of directory tree.

a)

To go up one level of directory tree, enter

$ cd ..

$ pwd
/home/smedia/test
$ cd ..
$ pwd
/home/smedia

c)

To change to directory pass directly enter.

d)

To change to home directory, enter:

$ cd test/pass
$ pwd
/home/smedia/test/pass
$ cd
$ pwd

/home/smedia
$

Chapter 2 : Unix File System


e)

To change to an arbitrary directory, type

31

$ cd /user/include

This changes the current directory to /user/include

$ pwd

/ user/include.
$ cd

This will change the current directory to home directory

$ pwd
/home/smedia
$

rmdir Command

This command is to remove the directory. But to remove a directory


with rmdir command, the directory must be empty, that is it must not
contain any files or sub-directories.

$ rmdir test
rmdir : test not empty
$

As test contains two sub-directories, so without removing these subdirectories, test directory cannot be removed. So to remove test
directory:

$ rmdir test/pass

test/fail

test

This command will first remove pass sub-directory and then fail subdirectory and after that test directory is removed.

$ ls
jet
$

met

So test directory and two sub-directories of test directory, fail and


pass has been removed and only jet & met directories has been left.
So to remove a directory, it should

be empty (should not contain files or sub-directories)


not be the current working directory

Because a directory can be removed only from its parent directories


and for that user must have write permissions in parent directory.

To remove the /test, /test/pass, and /test/fail directories, this


command can be entered.

$ rmdir -p /test/pass/fail

32

Chapter 2 : Unix File System

rmdir command with flag -p removes all directories along the path
name specified by the directory parameter. This first removes the /
met directory and then the /jet and
/test directories in order. If
a directory is not empty or does not have write permissions when it
is to be removed, the command terminates.

ls Command

This command displays the contents of a directory. The ls command


writes to standard output the contents of each specified directory or
the name of each specified file, along with any other information
which can be asked by using different flags with ls command. If a file
or directory is not specified the ls command displays the contents of
current directory. By default, the ls command displays all information
in alphabetic order by file name.

a)

$ pwd
/home/smedia
$ ls
identity jet

met

b)

To list all files, including hidden files, in current directory,


enter

met
$

d)

e)

true

This command has displayed all the contents of smedia


directory The information has been displayed in alphabetic
order.

$ ls -a
.
..

c)

new

new

.mail

true

.prof

identityjet

This lists all files, including


. (dot)(current) , ..(dotdot)(parent), and other files with names beginning with a dot.

$ ls -A

This lists all entries in the directory except . ( dot) and ..(dotdot). The result is same as in the Ist case because this flag A is used by default.

$ ls -C

This sorts output vertically in a multicolumn format. This is


the default method when output is to a terminal so information
displayed here will be the same as in the Ist case. The number
of columns depends on the length of the longest file name &
screen width.

$ ls /

Chapter 2 : Unix File System

f)
g)

h)

i)

j)

33

This will display the root file system. Here the/ means the root
of directories like - home, usr , var, bin, libh, dev, lost+found
etc.

$ ls - x

This command is same as ls -C but it sorts output horizontally


in a multicolumn format.

$ ls -m

identity, jet, met, new, true


$

This command displays output separated by comma with no


new-lines inserted.

$ ls -p
identity
$

jet/

$ ls r
true
$

new

met/

new

This command puts a slash { /} after each file name if that file
is a directory. Here it has put / after two directories jet and
met.

met

jet

identity

This reverses the order of the sort, giving reverse alphabetic


order.

Suppose you have a file named average under met subdirectory and to list all sub-directories recursively and to list
all sub-directories recursively, this command can be used.

$ ls -R
identity
./jet:
./met:
average

jet

met

new

k)

true

true

It has displayed nothing after jet sub-directory as it has no


files but average file has been displayed under met subdirectory.

$ ls -1
identity
jet
met
new
true
$

(Its one, not ell)

34

Chapter 2 : Unix File System

l)

This forces output into one entry per line format. This is the
default setting when the output is not directed to a terminal.

$ ls -l
total 48
-rw-rr
drwxr-sr-x
drwxr-sr-x
-rw-rr
-rw-rr
$

1 smedia

3
3
1
1

smedia
smedia
smedia
Smedia

gp

gp 512
gp 512
gp 1
gp 512

Jul 26 11.41

Jul
Jul
Jul
Jul

26
26
26
26

12:20
12.01
12.21
11:45

identity

jet
met
new
true

This command displays the detailed information about each


file. The information displayed consists of 1.

File modes

3.

Owner name

2.
4.
5.
6.
7

File Modes

No. of links

Group Name
file size

Date and Time of last modification


Fine name

The very first column displays the information about the file modes.
This information consists of 10 characters which varies from file to
file.
If the first character of information displayed is d

->

The entry is a directory

->

The entry is a character special file

b
l

->
->
->
->

The entry is a block special file.


The entry is an ordinary file.
The entry is a symbolic link

The entry is a Named pipe special file.

The next nine characters are divided into three set of three characters
each. For every file and every directory in the file system, there are
three classes of following users.
1. Owner
2. Group

The owner of file is the user who initially created


it. The first set of three characters show the
permission of owner.
Several users can be combined into a user group,
and so there is a group ownership associated with
each file and directory. The second set of three
characters shows the permission of group.

Chapter 2 : Unix File System


3. Public

35

It consist of all other users. Means, anyone who


has a user name and can gain access to the
system. The last set of three characters shows the
permission of against else who can access to file.

The three characters in each set indicate, respectively read, write and
execute permissions of the. So there are three basic authorizations.
r (Read)

w(Write)

x(Execute) -

A user who has read permission for a file can look


at the contents of that file. A user who has read
permission for a directory can find out what files
there are in that directory. If detailed information
about the files in directory is required (the -l
option to ls), the directory must have execute
permissions for the user.
A user who has write permissions for a file can
change the contents of that file. A user who has
write permissions for a directory can change the
contents of the directory- new files can be created
and existing files can be removed.
A user who has execute permissions for a file can
use that filename as a UNIX command, means a
file can be executed. A user who has execute
permission for a directory can change directory to
that directory and can copy files from that directory.

A right is granted if the corresponding letter is positioned. If there is


a dash, the corresponding right is refused.

So total there are 9 permissions for each of the group- User(Owner)(U),


group(G) and Others (O)
r

e.g.

rw-rr
rwxr-xr-x
rwxxx
rwxr-sr-x

No. of links

The owner can read and write the file or directory,


everybody else can only read it.

The owner can read, write, and execute the file ,


everybody else can read or execute it.
The owner can read, write and execute the file,
everybody else can only execute it.

This is same as in 2nd example. Here the group s execute permission character is as the file has
set group-ID mode.

No. of links for files is usually 1. If this no. is more than 1, it shows
that a number of identical copies of the file exist in different places
on the system. For directories, the number of links is an indication of
number of sub-directories in that directory plus two ( one for
directory itself and other for parent directory).

36

Chapter 2 : Unix File System

Name of Owner

Shows the owner of the directory or file. In this case the users or
owners name is smedia.

Name of Group

This shows the group of users that the owner is part of. In this case
the user smedia belongs to group called gp

Size of file

This shows the size of file in bytes. For text files the size of file is the
number of characters in the file.

Date and Time of Last modification

It shows the date and time of creation of file.

Name of file

In the actual name of file or directory.

m)

$ ls - al
total 64
drwxr-sr-x 1 smedia
drwxr-sr-x 1 smedia
-rw-rr 1 smedia
drwxr-sr-x
drwxr-sr-x
-rw-rr
-rw-rr

3
3
1
1

smedia
smedia
smedia
Smedia

gp 512
gp 512
gp 1

gp 512
gp 512
gp 1
gp 512

Jul 31 12:36
Jul 28 15:35
Jul 26 11.41
Jul
Jul
Jul
Jul

26
26
26
26

12:20
12.01
12.21
11:45

.
. .
identity
jet
met
new
true

ls has an enormous number of options, but the ones presented so far


are adequate for the time being. The important options are summarised
below.
Option

Description

-X

Displays multicolumnar output (prior to Release 4)

-r

Sorts files in reverse order (ASCII collating sequence by


default)

-F

Marks executable with *and directories with/

-I

The long listing showing seven attributes of a file

-a

Shows all files including.,.. and those beginning with a dot

-d
-t

-R
-u
-i

Forces listing of a directory

Sorts files by modification time

Recursive listing of all files in sub-directories

Sorts files by access time (when used with the -t option)


Shows i-node number of a file

Chapter 2 : Unix File System


-c

Sorts by time of change of the i-node

-l

One file per line (Release 4)

-s

37

Displays number of blocks used by a file

group Command

As mentioned earlier, every one on a UNIX system is assigned to a


group, and one than more groups can be assigned to one user. When
you login a UNIX system, youve automatically placed in the group,
which can be found listed in the /etc/passwd file.

To find out the groups, you are assigned to, groups Command can be
used

$ groups
gp
group1
$

The above information tells you that you are a member of gp and
group1 group. Information about groups and their member can be
found in /etc/group file, which is readable file. However, on a large
system, this file could be extremely large so grep command (will be
discussed in detailed at a later stage) can be used:

$ grep smedia \etc\group

gp
: 120 : smedia, Hare,
group1 : 421 : Kathrine, smedia, John
$

The above information display the member of each group and the
group IDs(120 for gp, 421 for group1). The information is important,
if the group is to be switched during normal work. The group can only
be switched if you are member of the new group. That can be done
using the newgrp command.

$ newgrp group1
$

chmod Command

As discussed earlier, the first column (last when read form right to
left) display the permission to different levels of permission. There are
read, write and execute.
The above three permission can be applied to files as well as directories.
When applied to files, read permission means that the you can change
the file and the execute permission means that you can run the file
as a program.

38

Chapter 2 : Unix File System

Permission can also be applied to directories. Read permission means


that the contents of the directories can be listed. Write permission
means that the files and directories can be made within the directories
and the execute permission means that you can make that directory
your current directory via cd command.
As discussed earlier, the nine columns display the permission available
for user (rwx), group(rwx) and other (rwx).

The above method of listing permission is the symbolic method, which


is one of two ways of listing UNIX system tracks permission. The other
method is numeric form, which is comparatively handy changing
permission with chmod command.

Setting Permission Numerically

The numeric form uses modes to list permission. A mode is an octal


number in one of the forms listed below.
400

Owner has read permission

100

Owner has execute permission

200

Owner has write permission

040

Group has read permission

020

Group has write permission

010

Group has execute permission

004

All users have read permission

002

All users have write permission

001

All users have execute permission

You get the numeric form by adding together the number and then
combining that member with chmod command. (short for change
mode).
Consider the following example:

-rwxrr

smedia

gp

Jul 26 11.41

identity

The above Symbolic form can be translated to numeric form a follows400 (r)

read permission to owner

100 (x)

execute permission to Owner

200 (w)
040 (r)
004 (r)
____
744

write permission to Owner


read permission to Group

read permission to all users.

Thus by adding each value associated with each level of permission


the numeric form can be obtained. Thus, a file with numeric value
777 will be assessable to everybody including owner, group and
users, and a file with numeric value 000 will be inaccessible to
everybody.

Chapter 2 : Unix File System

39

$ chmod 777 identity


$

The above command will change the permission for the file identity to
everybody ( including owner, group and all users), the following
command can be used :

$ chmod 700 identity


$

The above command will change the permission to where only the
owner has the ability to read write and execute file identity.

$ chmod 770 identity

The above command will change the permission to where the owner
has the ability to read, write and execute the file, with members of the
group also having the ability to read, write and execute.
To change the permission of the contents of the entire directory with
chmod, -R can be used as a switch.

$ chmod -R 700 jet

The above command will make entire contents of jet sub-directory


readable, writable and executable to the owner of the directory.

Setting permission Symbolically

Symbolic method can also be used to set the permission but it is


different than numeric method in the respect that in the numeric
method the parameters are set parameter are while in this method,
the new permission are set relative to the old one.

In the symbolic method the permission is added or subtracted


through a switch along with chmod the symbols used with chmod
command are.
u

User ( or the owner of the file )

Other

+
-

w
x
e.g.

$ ls -l identity
-rwxrr

group

Adds a permission to the existing permission

Takes a wa y a per m ission from th e ex is tin g


permission
Reads the file.

Write to the file.

Executes the file.

Sets the sticky bit on a directory.

smedia

gp

Jul 26 11.41 identity

40

$ chmod g+x o-r identity


$

Chapter 2 : Unix File System

The above command will add the executable permission to the group
and takes away the readability permission form all users.

$ ls -l identity
-rwxrr

smedia

gp

Jul 26 11.41 identity

Thus 777 code in numeric method is equivalent to ugo+rwx symbol


in this method

i.e.

$ chmod ugo + rwx identity

umask Command

When a file or directory is created default permission are automatically


assigned to file or directory. Most of the times, there permissions are
acceptable, but at times these are required to be changed. This can
be done by using the umask command ( Short for user mask). When
run without any option it returns the value of default permission

$ umask
744
$

To changed the default permission the parameters are given along the
umask command, but it must be noted that within the UNIX system,
the umask command changes permission relative to a baseline of
777. Thus the command umask 007 is giving input the baseline 770,
thus giving a final permission of 770.

$ umask 007
$ umask
770
$

SECURITY AND UNIX FILE SYSTEM

Security is not an absolute in UNIX. Some security breaches occur


because a group of people wants to show how clever they are. About
the UNIX system it must be remembered that -

No form of Security within UNIX is absolute

Setting the proper permission is the most basic level of security


possible. But the system administrator, who is logged in as the root

Chapter 2 : Unix File System

41

user or the superuser, has access to all files on the system. A


resourceful intruder always attempts to login as the root user.

Never take anything for granted it comes to security

Even if you take other more advanced security steps (as youll learn
about when you learn about networking and communications), your
data may still be vulnerable. Plan accordingly.

If theres anything ultrasensitive, dont store it on the UNIX system


While this is a fatalistic attitude not necessarily shared amongst the
greater UNIX community, its our belief that ultrasensitive information
shouldnt be stored on a UNIX system, no matter how good the
security is. (This is one of the few advantages a DOS system has over
UNIX : You can physically lock up a DOS system with a key, and you
can keep information personal in the form of a floppy drive or a
removable tape.)

cat Command

A file can be created by typing cat > filename and pressing RETURN.
Then contents of file can be typed and Ctrl-D (Ctrl-D is the UNIX endof-file marker) is pressed to end this file.

$ cat > identity


Name
address
Age
^D
$

:
:
:

smedia
KJ-75, Kavi Nagar, Ghaziabad.
3

Here the > symbol informs shell to redirect output (discussed later)
of the cat command to a file identity.
Now to display the contents of above file type -

$ cat identity
Name
:
address
:
Age
:
$

smedia
KJ-75, Kavi Nagar, Ghaziabad.
3

Now to add text to the end of a file, enter:

$ cat >> identity


Phone No. : 001 - 0120 - 4702867
^D

42

$ cat identity
Name
:
address
:
Age
:
Phone No.

Copying a file

Chapter 2 : Unix File System

smedia
KJ-75, Kavi Nagar, Ghaziabad.
21
001 - 0120 - 4702867

Using cat command, a file can be copied to another by simply


redirecting the output to a file.

$ cat oldfile > newfile


$

This will copy the old file into the newfile. The command is a
combination of cat reading the source file and the shell redirecting
the output to a file.

Concatenating Files

cat commands main purpose is to concatenate files i.e. if more than


one file name is specified, all files are concatenated ( joined end to
end) and copied to the standard output (usually your terminal screen)

Display Multiple Files

To display more than one file, simply name more than one file on the
command line.

$ cat identity new true.


Name
: Smedia
Address
: KJ-75, Kavi Nagar, Ghaziabad.
Age
: 21
Phone No.
: 001 - 0120 - 4702867
Identity is new
Identity is true
$

Here first four lines are from file identity, next one is from file new and
last line is from file true. So there is no notification of when a file ends
and the next one begins. The input is combined into one contiguous
output stream
Instead of sending this displayed information to terminal, it can be
sent to a file by using

$ cat identity false true > new


$ cat new

Now you will get the new files which contains contents from identity,
new and true file.

Chapter 2 : Unix File System

43

pg Command

To look at a large file, it is better to use pg command. This command


gives pagewise output on screen and page size is equal to the size of
terminal screen. Suppose you have 24 line screen, then only first 23
lines of file will be displayed and a : prompt will be displayed on 24th
line and for next page, a RETURN is to be pressed.

$ pg filename

At any page of file, type q or Q followed by a RETURN, to exit from pg


without displaying the rest of the file.

more Command

While viewing large files, you often find the output scrolling off you
screen. This sometimes happens so fast that, before you hit <Controls> to stop it, quite a bit of the output would have scrolled off. Using
<Control-s> and <Control-q> alternately is certainly not a comfortable
method of halting the output. It also doesnt let you see what has
already been seen before. UNIX offers the more command as a paging
tool, so that you can view one page at a time.
A product of the University of California, Brerkley, this command has
now made its entry into several versions of UNIX (especially XENIX).
It is now offered in Release 4. Based on pg, the original pager of the
UNIX system, more, allows the user to view a file, one screen at a time.
This chapter present more, in preference to pg. Because it is in may
respective superior to pg. For installations not having more, use pg.
instead, which is similar in operation.
The syntax of the more command is a follows :

more <options> <+line number> <+/pattern> <filename(s)>

You really don't need to use more compulsorily with such a complex
command line, except for the filename (strictly speaking, even that is
not), the rest are optional. To view the file chap01, simply enter the
command with the filename:

$ more chap01

You will see the contents of chap01 on the screen, one page at a time.
Normally, the message ...More..., along with the percentage of the
file tat has been viewed, is displayed at the bottom of the screen. But
there can be variations in the message it displays, depending on the
brand of UNIX you are using. You can advance to the next page by
pressing the spacebar (or <Enter> in some cases). To quit the more
program, simply press q (quit).

44

Chapter 2 : Unix File System

More also works with multiple filenames.

$ more chap01 chap02 chap03

You first see the contents of the first file, preceded by its name. After
you have finished viewing this file, more pauses with the message
.....More...(Next file : chap02) , before displaying the contents of the
file chap02. In this way, it sequentially displays all the files, pausing
additionally whenever a change of file occurs.

More has a couple of internal commands of its own, which dont show
up on the screen when you invoke them. In other words, you can use
certain key sequences inside the more program to act on the output.
Many UNIX utilities like ex, vi, mail and sed also have their own
internal commands.
In the middle of a session, you can always switch to the next file, by
entering the two-character sequence

:n

or to the previous file by using

:p

At any time, you can know the filename, as well as the line number
that you are on, by using

:f

More is very useful in locating lines which contain a pattern. Simply


press a/, followed by the text you are looking for. Thus, to look for
the word UNIX, you should use

/UNIX

If that is not the pattern you are looking for, then you can press n
repeatedly till you have located the desired line. The mechanism of
locating a pattern and repeating a search is identical in the vi editor,
also from Berkeley.

file Command

Even though there are basically three types of files (ordinary,


directory and device), you may often require to know more about
these files. For instance, it is possible that two files may be of the
same type (e.g. ordinary), but one may contain text, while the other
contains executable code. UNIX provides the file command to
determine the type of file, especially an ordinary file. The command
is simple to use, and you can use it with one or more filenames.

$ file emp.Ist
emp.Ist:ascii text
$-

Chapter 2 : Unix File System

45

When the command is used to apply to all files in the progs directory,
you will see an informative list (use the *again to indicate all files) :

$ file progs/*
abcd:
ascii text
calender
compchk.sh:
helpdir:
textl;
progl.C
$-

English text
commands text
directory
date
c program text

od Command

Many files (especially executable) contain non-printing characters,


and most UNIX commands wont show them properly. The od (octal
dump) command displays the ASCII octal value of any files contents.
Each characters is replaced by its octal value. The file odfile contains
some of these characters which dont show up normally :

$ cat odfile
White space

$ od -b odfile
0000000 127 150 151 164 145 040 163 160 141 143 145 040

When used with the -b option each line displays sixteen bytes of data
in ASCII octal format, preceded by the position in the file of the first
line contains the letter W, which also has the octal value 127. This
methods of identifying characters may not be attractive enough to
warrant the extensive use of od, but when combined with the -c
(character) option, the output is friendlier :

$ od -bc odfile

Each line is now replaced by two . The printable characters are


shown normally in the first line while their octal representations are
shown in the second.

0000000

cp Command

W h i t e
s p a c e
127 150 151 164 145 040 163 160 141 143 145 040

This command copies files means it creates a copy of contents of file


or directory and so cp command takes two arguments. The first
argument is the source file or source directory parameters which

46

Chapter 2 : Unix File System

specifies the name of file or directory to copy from, and the second
argument is the target file or target directory parameters which
specifies the name of file or directory that we want to be the copy cp
commands can copy.

A file to another file

A directory to a directory.

Files to a file or directory

If the file specified by target file already exists, the copy writes over
the original contents of the file so be careful, when this command is
used. Files maintain their respective names when copies to a directory
unless you specify a new name file at the end of path.

a)

At present we have files

$ pwd
/home/smedia
$ ls
identity
jet
met
$ cp identity identity.doc
$ ls
identity

b)

identity.doc

jet

new

true

met

true

The above cp command makes a copy of file in the current


directory. If the identity.doc does not already exist, then the
cp command creates it. If it exists already, then the cp
command replaces it with the copy of identity file. The created
file identity.doc will have current date and time stamp. This
can be checked with ls -l command.
To copy a file to a new file and preserve the date & time
associated with the source file enter.

$ cp p identity true.doc

c)

This copies the identity file to true.doc file and instead of


creating the file with the current date and time stamp, the
system gives the true.doc file the same date and time as the
identity file.
To copy a file in your current directory into another directory,
enter

$ cp identity /home/smedia/met/identity.doc
$ ls met
average identity.doc

To make a copy with the same name do not give the target file name.

d)

$ cp identity
$ ls met
average

/home/smedia/met
identity

identity.doc

To copy all the files in a directory to a new directory, enter:

Chapter 2 : Unix File System

e)

$ cp /home/ smedia/met/* /Home/smedia/jet


$ ls jet
average
identity
identity.doc

47

To copy a directory, including all its files and sub-directories,


to another directory, enter:

$ cp -R /home/smedia/jet /home/smedia/met

f)

The above command will create a jet sub-directory under met


directory which will contain all the files and sub-directories of
jet directory
To copy more than one file at a time

$ cp

new true

/home/smedia/jet

To copy all the files with same extension use.

$ cp /home/smedia/met/*.doc .

This will copy all the files in met directory, to the present working
directory, signified by the single.(dot).

mv Command

mv command moves files and directories around in the file system. In


this process of moving, it can rename files or directories and this
renaming is just a side effect of this command and not the actual
purpose. So move (mv) command moves files and directories from one
directory to another, or renames a file or directory.

a)

To rename a file, enter

$ mv new new.doc

This renames new to new.doc. If a file named new.doc already


exists, its old contents are replaced with those of new. So be
careful and to avoid this always specify -i. flag. The -i flag
prompts you to confirm before it overwrites a file. Now if you
give :

$ mv - i true new.doc.
overwrite new.doc? n
$

b)

As new.doc already exists so before over writing the file, it


asks for the confirmation. If you ensure with y the move
continues. Any other reply prevents the move from occurring.
To move a directory

$ mv jet met

This moves all files and sub-directory under jet directory to


the directory named met. In case met directory does not exist,
the directory jet is renamed to met.

48

c)

Chapter 2 : Unix File System

To move a file to another directory and give it a new name,


enter :-

$ mv new.doc jet/new1.doc

d)

This moves file new.doc from current directory and same file
appears with name new1.doc in pass directory.
To move a file to another directory, keeping the same name,
enter:

$ mv
$

e)

true jet

This moves file true to jet/true.

To move all the files with the same extension ; enter:

$ mv jet/*.doc .
$

This moves all the files with extension *.doc into the current
directory with the same names.

$ mv jet/* .
$

This will move all the files and sub-directories from jet directory
to current directory and will empty jet directory.

rm Command

This command removes files or sub-directories. To remove a file, it is


not required to have read or write permissions for the file. However,
directory containing that file must have write permissions.

a)

b)

c)

To delete a file, enter:

$ rm identity.doc
$

This will remove file named identity.doc from current directory.


To delete more than one file at a time, enter

$ rm true true.doc identity identity.doc.


$

This command will remove all five files from current directory.
If any of these file does not exist, then it will display a message
that A file or directory in the path name does not exist.
To delete files one by one, enter

$ rm - i
$

fail/*

It will display all the filenames one by one, for confirmation


and enter y to delete the file, or press the enter to keep it. But

Chapter 2 : Unix File System

49

this command can remove only the files within this directory
and if this fail directory contains any sub-directory will
display the message that this directory cannot be removed
like for above it will display -

rm
rm
rm

d)

rm

: remove jet/average ? y
: Remove jet/identity ? y
: Remove jet/identity.doc ? y

: 0653-603 can not remove directory jet/met.

To delete a directory tree,

$ rm -ir
$

met

This command recursively removes the contents of all subdirectories of the met directory, and prompts you regarding
the removal of each file, and then removes the met directory
itself. If you deny permission to remove a sub-directory, the
rm command does not remove the met directory.

WILDCARDS

So far our discussion has centered about the manipulation of single


files and directories. UNIX provides an amazingly powerful tool,
called wildcards, that allows you to manipulate files at one time, with
a single command. Wildcards are a kind of shorthand that allows you
to specify similar files without having to type multiple names. And
wildcards allow you to search for files even if you dont remember the
exact name.
There are three types of UNIX Wildcards: *, ? , and [..].

In every instance in this chapter where weve used single filenames


you could use a wildcard. Lets go back to the ls command. Lets say
you want to find all files in your directory ending with in string report.
You could use the ls command in conjunction with a wildcard:

$ ls * report
a.report b.report

smedia.report

These three files represent the number of files in the current directory
ending in the string report.

The asterisk wildcard is used to match any number of character in a


string (including zero characters). It can be used anywhere in the
string. If you wanted to list the files beginning with the string report,
you would use ls along with the following wildcard:

$ ls report *
report.new

report.old

reporter.old

If you wanted to list the files with the string report some where in the
filename, use:

50

Chapter 2 : Unix File System

$ ls *report*
a.report
newreport91
oldreport92

b.report
newreport92
report.new

reporter.old

smedia.report
oldreport91
report.old

Note that weve received a list of files that both end and begin with
report, as well as the files with report in the middle of the filename. As
we said, the * wildcard can be used to match any number of
characters in a string. In this case the wildcard matched zero
characters.
Conversely, the ? wildcard is used to match a single character in a
string:

$ ls report?
report1

report2

report3

report4

In your example the ls command did not return report.b as a match.


Thats because there are two characters following the string report,
and we only asked for one. As with the asterisk wildcard, the ?
wildcard can appear anywhere in a string.
You can combine the *and ? wildcard:

$ ls ? report*
lreport1991

2report 3report92

To return the filenames of all files beginning with a single character


followed by the string report and ending with any number of characters.

The final wildcard option is denoted by brackets. Here you can ask
UNIX to match specified characters:

$ ls report199[01]
report1990

This becomes especially useful when youre looking for files and
youre not entirely sure of the case (remember, UNIX distinguishes
between uppercase and lowercase characters) :

$ls report. [Ee]rc


report.Erc
report.erc

You can also use a hyphen to denote a range of character between


brackets:

$ ls report[a-d]
reporta
reportb

reportc

reportd

This command did not return filename reporte, because it did not fall
in the range of characters defined within the brackets.

Chapter 2 : Unix File System

51

Even through weve used the ls command in our examples, wildcard


can be used with any UNIX command - rm, mv, cp, and so on.

$ ls */*
Arguments too long.

If you see such a message, your only recourse is to create a command


that takes a much smaller number of parameters. For example, you
could ask for all files in directories that begin with uppercase letters:

$ ls [A-Z] */*

Then ask for all files in directories that begin with lowercase letters:

$ ls [a-z] */*

Whatever method you use, you must find a way to divide up the
number of files passed on the command line.

Even through weve lectured you about the necessity of good file
organization, its inevitable that youll lose track of a file - and usually
the more important the file the more likely youll lose track of it.

UNIX features a powerful command, find, that helps you locate the
wayward file. Lets say that youve misplaced a file named 2001.data.
If youre truly masochistic, you use the following command to find it:

$ find / -name 2001.data -print

In this case UNIX searches for the file 2001.data in every directory
and sub-directory in the entire system. If youre working on a large,
multiuser system with hundreds of megabytes of storage space, it can
take quite a while to find this file - especially given the fact that
2001.data is not exactly a distinctive filename and that theres a very
good chance that another user may have appropriated the same
name. Even on a single-user system with 300 or 600 megabytes of
hard-disk space the search can take too long.
Its best to use the find command with some limitations, such as
specific directories. Lets say we know that the file 2001.data is
located some where in the /user directory. We user the following to
narrow the search criteria:

$find /users -name 2001.data -print


/users/home/data/2001.data
/users/kevin/data/2001/2001.data

Lets say you dont remember the exact name of the file; you know that
you created it sometime in the 2000s but dont remember the exact
year. Since youre an organized user and denote all your files with the
year as a prefix, you could use a wildcard to search for all files
beginning with the string 200:

52

$ find - name 200* -print

Chapter 2 : Unix File System

When using the -name option, be sure to enclose your search string
in quotes. UNIX is rather quirky on this point and perhaps over
complex. The reason for this is that the command interpreter ( called
shell in UNIX parlance) would expand the 200* to mean the name of
every file in the current directory that starts with 200 - which is most
definitely not what you intended.

Finding Files in the background

Unix is multitasking operating system, which means it can perform


more than one task at a time. Under these circumstances you may
want to run the find command in the background; this allows you to
perform other tasks in the foreground while UNIX looks for the file.
To search for the file 2001.report in the background, end the command
with an ampersand:

$ find / -name 2001.report -print &

This tells UNIX to search for the file 2001.report beginning at the top
of the file structure with the root directory and moving downward,
and alerting you when the file is found. The ampersand (&) tells UNIX
to perform this task in the background .

However, you may not want to be alerted when the file is found,
particularly if there are potentially many instances of the file. To print
the results to a file instead of to your screen, insert the > symbol as
well as a filename in the command:

$ find / -name 2001.report -print > results &

This directs the output of the search to the file results. In general, the
> command will direct the output of a command to a file; well use the
> command may times throughout the course of this book.

There are two ways in which we can have the output from the
computer.

Softcopy

Soft copy is the copy of a file that is stored on a disk somewhere in the
file system. It exists as electronic or magnetic patterns somewhere in
the computer system.

Hardcopy

Hardcopy is the copy of a file which is taken with the help of printer
on a paper. It exists in the real world. It can be run, can be felt, and
can be seen, can be felt, and can be read and thats why it is called
hardcopy.

Chapter 2 : Unix File System

Here we will take two commands lp and lpr to print the files.

53

lp Command

This command send request to a line printer. The lp command


arranges for the files and associated information [called a request] to
be printed by a line printer. If no files are given, the standard input
is assumed.

$ lp this file nofile yesfile


request id is 175 [3 files]

This command responds with a line of text which tells you what
identity has been allocated to your print request. This number will be
required when you later decide that you do not want the printout after
all.

a)

-n option

$ lp -n 3 tfile

This command prints three copies of tfile. The default number


of copies is 1.

b)

- m option

c)

- w option

If this option is used with lp command, it notify user by mail


when the file has been printed.
This option is similar to -m, but a message sent to terminal
using the write command when the file has been printed.

lpr Command

lp command in used to print files in System V, while in UNIX System


V Release 4 uses lpr command to print a file.
a)

$ lpr filename

b)

$ lpr file*

After running this command also the system will list the print
and will generate an ID number so that if user can check the
status of printing at a later line.
This command will print all files that begin with the string
file.

lpstat Command

The lpstat command displays information about the current status


of the line printer. It prints the status of all requests made by the l p
command.

a)

To display the status for all print queues, enter:

$ lpstat

54

Chapter 2 : Unix File System

b)

To display the long status for all printers, enter

$ lpstat - t

cancel Command

The cancel command cancels line printer requests that were made by
the lp command. Syntax of this command is

Cancel {JOB ID I Printer Name}

Either JOBID or printer name in to be given. Specifying a JOBID


cancels the print request, even if it is currently printing. Specifying
a printer name cancels the printing of your jobs on the specified
queue. If you have root user authority, all jobs on the queue are
deleted.

$ cancel 173.

This command will cancel the printing of file with job ID No. 173.

banner Command

The banner command creates posters by blowing up its argument on


the screen. On each line it can display a maximum of ten characters.
If you are to display the word UNIX on the screen, then this is how
you can use this command:
$ banner UNIX
#

#
#
#

$ -

#
#

#
#

#
#
#
#
#

###

#
#

###

#
#

This is the size used by lp to print the user name on the title page.
There are no options, and it is simple to use.

Chapter 2 : Unix File System

55

UNIX uses files for just about everything. Every document


created in UNIX is a file. Every command you run is a program
stored in a file on disk. Even printer is a special file. There are
four classes in the file types :
Ordinary files
Directories
Links

Special file

Every file has access permission, based on user (the owner of


the file), the owners group, and everyone else (called world
permission). These permission include the ability to read,
write, and execute the file as a command. For files, there are
three levels of permissions which includes : Read permission
means you can read the file, Write permission means that you
can change the file, and execute permission means that you
can run the file as a program.

UNIX uses a hierarchical file system. At the top of the tree is


the root directory, usually represented by a slash (/). each
user on a UNIX system is given an account, with a home
directory. For a user named smedia, the home directory might
be /users/smedia.
pwd command displays the current working directory. To
change the current working directory use cd. mkdir command
creates the new directory. To get rid from any empty directory,
use rmdir.

ls command displays the contents of the directory. Use ls -l


option to display the complete permission of the owner, group
& others. This permission can be changed by using chmod
command. chmod can use either the numerical method or
symbolic method. umask command can be used to change
the default permission. While displaying the details of
directories, ls command also displays the groups, you are
working in. To display all the groups you are assigned to, use
group command. To change the group among the assigned
groups, use newgrp command.
Files can also be created in the specified directories using cat
command. It can create following functions :
1.

display the existing file (cat filename)

3.

copy a file (cat oldfile > newfile)

2.
4.

5.

create the new file (cat > filename)

merge two or more files (cat file1 file2 > file3)

To print the file on printer ( cat filename | lp)

cp command can also be used to copy the files from one file
to another, from one directory to another etc.. mv command
can be used to move the file from one place to another. rm

56

Chapter 2 : Unix File System

command can delete the file. Wildcards *, ?, & [...] can be


used with file name to apply commands on similar type of
files.
To locate the file on the harddisk, use find command. lp and
lpr command can be used to get the printouts of the files.

Chapter 2 : Unix File System


1.
2.

a.

List six uses of the cat command.

c.

Write the command to combine file1 and file2 into file3

b.

4.

5.

How can you stop and start scrolling?

a.

What is the purpose of the cd command.?

c.

Write the command to return to the previous directory.

b.
d.

3.

57

Write the command to change directories to your


parent directory.
Write the command to change to the user njf HOME
directory.

a.

What is the purpose of the chmod command?

c.

Write the previous command using absolute modes.

b.

Write the symbolic mode and numeric mode command


to change the permissions on file1 to read and write
for all users.

a.

List the four uses of the cp command.

c.

Explain the command cp file1/etc/tty.

b.
d.

Define source file and destination file.


Explain the command cp file1 file1.

a.

What is the function of the lp command?

c.

Write the command to print the/etc/group file to the


laser printer.

b.

How do you suppress the request information message?

6.

a.

What does the lpr command do?

7.

a.

What function does the ls command serve?

c.

Write
t h e com m a n d t o d i s p l a y n o n - p r i n t a b l e
characters.

b.
b.

d.
e.
8.
9.

Write the command to print file1 to the HPLJ printer.


Write the command to display all files in all subdirectories.
Explain each position of the modes.

Write the command to allow other users to execute a


program as through they owned.

If the current path is /home/export/down and the relative


path is /arrive/source/m.c what will be the absolute path.
Which of the following are invalid filenames & why? Give
reasons.
a)

new letter

c)

a.b.c.d.e

b)
e)
f)

This_is_a_letter_to_my_friend (on SVR4)


eatable
groups

58

10.

State True or False:


a)

Lies and LIES are the same files.

c)

mkdir command can create many directories with


same command.

b)

d)
e)
f)
11.

g)

13.
14.

An inode is the record that stores most of the


information about the specific file on the disk.
rmdir used with -p command will delete all the
directories & subdirectories.

chmod -R 744 will change the permission of the entire


directory as -rwxrr.

pg command is used to display the contents of the file


in pagewise manner.
cp command can copy only one file at a time.

You create a file called tonky in the directory honky.


a.

b.
12.

Chapter 2 : Unix File System

What information is stored about honky in tonky?

Later, you add new material to tonky. What changes


take place in the directory, and file.

How could you restore write permission for yourself and for
other group members for the file oddities?

What command would give you read, write, and execute


permission, group members read and execute permission,
and give others just permission for the file look?
How can you use cat to create a file tale consisting of
keyboard input sandwiched between the contents of two files
start and end?

Chapter 3
UNIX TOOLS
UNIX TOOLS
FINDING TEXT PATTERNS IN A FILE(S)
SORTING FILES
SPLITTING A FILE APART
FILE COMPARISONS
CUTTING FILES
MERGING FILES
COUNTING THINGS IN A FILE
CHECKING SPELLINGS
VIEWING NON-ASCII FILES

60

Chapter 3 : Unix Tools


Much of the hidden power in the UNIX operating system lies within
the various utilities summoned from the command line. While these
utilities may not appear to be overwhelmingly powerful individually,
they do the job, and they do it well and efficiently. These tools can be
used by themselves or in conjunction with other commands to create
even more-powerful combinations.

grep Command

Weve all done it: needed to find a nugget of data and couldnt
remember exactly where we stored it. Instead of manually searching
through the hundreds of files on our system, we can invoke three
UNIX tools : grep, egrp and fgrep.
The grep in a utility program that searches a file, or more than one
file, for lines which contain strings of a certain pattern. Lines which
match the specified pattern are printed on standard output.

a)
b)

$ grep smedia softperson


smedia clark 105

It can tell the rank of smedia clark this way.


To scan more than one file at the some time.

$ grep smedia softperson hardperson adminperson.


softperson : smedia clark 105
$
OR
$ grep smedia *person

c)

will scan all the files ending with person.

$ grep Ram Ganga person


Ram Ganga

99, G.T.Road

Ghaziabad

To have grep search for a phrase containing a space, we must


enclose the phrase in quotation marks. If we dont use quote
here:

$ grep Ram Ganga person


grep
: cant open Ganga
person : Ram Ganga
99, G.T.Road
$

Ghaziabad

We get the error, because the program is trying to look for


Ram in the files Ganga and person.

Chapter 3 : Unix Tools


d)

If we cant remember the exact file containing the string Ram


Ganga, we could use a wild card to have a grep search
throughout all the files.

$ grep Ram Ganga *


mail
: Ram Ganga
Computers
person : Ram Ganga
99, G.T.Road

a)
b)
c)

61

Limited
Ghaziabad

Although the grep command is quite powerful to do a search,


yet some rules must be remembered while using grep.

Grep searches one line at a time. If, in our example, Ram and
Ganga had appeared at two different lines, grep would not
have reported a match.
Grep looks for strings of text and does not limit itself to the
whole words. A search for the string town could return the
lines containing the words mini-town, downtown & town.

Grep can be used with wild cards to search for patterns.


Suppose you want to search for Ganga Galaxy, but as per
rules you know that if two word appears on different lines,
grep would ignore them. In this case, a wild card could be
used to return all instances of words beginning with Ga.

$ grep Ga* *

d)

e)

Here two wildcards appeared in the command. The first


instance tells grep to search for any word starting with Ga,
the second instance tells the grep command to search through
all the files in the current subdirectory.

Grep distinguishes between the uppercase & lowercase letters,


unless told otherwise. To tell grep to ignore case, use -i
option.

$ grep -i Ram Ganga *

If you dont want grep to list the lines of text matching the
specified string, use the -l(ell, not one) option to list only the
file names.

$ grep -l Ram Ganga *


mail

f)

person
$

If it is required to search for the lines not containing the


particular string, use grep as antisearcher, by using the -v
option.

$ grep -v Ganga person


Virtual Tekware
4, Gandhi Nagar
Digisoft Consultant
KJ-75, Kavi Nagar
$

Ghaziabad
Delhi

62

Chapter 3 : Unix Tools

egrep Command

While egrep supports all the function of grep, it goes a step further
and allows the searching of multiple strings. For example, multiple
companies are to be searched in the same file. It can be done by
combining the names of the companies with a pipe symbol within
quotation marks:

$ egrep Ram Ganga| Virtual Tekware person


Virtual Tekware
4, Gandhi Nagar
Ram Ganga
99, G.T.Road

fgrep Command

Ghaziabad
Ghaziabad

fgrep (shorthand for fast grep) works similarly to egrep, but instead
of using a pipe command and quotation marks to specify the text,
each item must be placed on its own line.

$ fgrep Ram Ganga


V irtual Tekware *
mail
: Ram Ganga
person : V irtual Tekware
person : Ram Ganga

Computers
4, Gandhi Nagar
99, G.T.Road

sort Command

Limited
Ghaziabad
Ghaziabad

Sort in a utility program which sorts the contents of a file into


alphabetic or numeric order. There are many options which control
the sort order. This command also merges files that are already
sorted, and checks files to determine if they have been sorted.
Suppose we have a file of city names and their STD codes.

$ cat Code
DELHI
CALCUTTA
BOMBAY
MADRAS
$

011
033
022
044

And if above file is sorted, its output will be

$ sort code
BOMBAY
CALCUTTA
DELHI
MADRAS

022

033
011
044

Chapter 3 : Unix Tools

63

Suppose we have another file of names of persons and their rank


numbers which in to be sorted.

$ cat person
RASHMI SYAL

100

SANJEEV CHAWLA
RICHA VASISTHA
CHARLIE SMITH
AMBICA CHAWLA

99
125
114
105

$ sort +1 person
SANJEEV CHAWLA
AMBICA CHAWLA

99
105

To sort above file on last name, type

RASHMI SYAL
CHARLIE SMITH
RICHA VASISTHA

100
114
125

Each line in the file is considered to consist of fields, the fields being
separated by spaces. So to get file in order of last name, program is
told to skip one field [the first names] by specifying it by +1.
To sort first on last names and then on first name, type :

$ sort +1 -2 person
AMBICA CHAWLA
SANJEEV CHAWLA
RASHMI SYAL
CHARLIE SMITH
RICHA VASISTHA

105
99
100

114
125

99
100
105
114

The above command skips one field before it starts sorting [ first
names], then it stops sorting after the second field [last names]. When
sort stops sorting after the second field, it then resumes sorting from
the beginning of line again, so it sorts on first names and rearranges
names AMBICA & SANJEEV.

Sorting into Numerical Order


$ sort -2n +1 person
SANJEEV CHAWLA
RASHMI SYAL
AMBICA CHAWLA
CHARLIE SMITH
RICHA

VASISTHA

125

64

Chapter 3 : Unix Tools

n in used to treat the fields as numbers and to sort according to


arithmetic values of those nos. and using n ignores the spaces. + 1 is
to specify the ordering of second field in case of same rank nos.

Sorting into reverse Numerical Order


$ sort +2nr -1

person

The use of r to reverse the order of sort in not restricted to numeric


sorting but for numerical sorting it is most commonly used. But we
can use +1r and +0r to produce the names in reverse alphabetic order
in this case.

Saving Sorted Output

$ sort -o sperson +1 -2 person

Till now, we displayed output of sort on terminal screen. -o [output]


options saves the output of person file into sperson file. You can also
use:

$ sort +1 -2 persons > speople

This will also redirect the output to speople file.

Merging already Sorted files

Suppose we have three files of different persons - softperson,


hardperson, and adminpeople and we want to merge three files into
one file person.

$ sort +1 -2 softperson hardperson adminperson > person

OR $ sort +1 -2

*person > person

Here the contents of all the files named are joined together, end to
end, and the composite is then sorted.
If input files are already sorted, it can be merged by using the -m
[merge] option.

$ sort +1 -2 softperson > sperson

$ sort +1 -2 hardperson > hperson


$ sort +1 -2 adminperson > aperson
$ sort -m +1 -2 spersopn hperson aperson > newperson

And in result we get softperson, hardperson, and adminperson all


together sorted into order.

Duplicating Lines in sorted files

When we merge files, we can get duplicated lines i.e. it is quite


possible that one entry is being repeated in files to be merged and
these entries will appear duplicated in the output. To get rid of
duplications, -u [unique] option can be used:

$ sort -u

-1 *person > newperson

Chapter 3 : Unix Tools

65

split Command

This command will split a file into pieces. This command is useful to
split big files which are too large to fit in the help of editors.

a)

b)

$ split bigfile

This command will split begfile into 1000 line segments and
each part gets put into a different file in the current directory.
The names of output files are generated by using the letter x,
followed by two more letters. The first output file name will be
xaa and so on through xaz and then xba and so on right
through xzz. Each of the file produced except the last, will
contain 1000 lines. The no of lines in last file will be whatever
was left over a multiple of 1000.
To control the number of lines in the output file, following
command should be typed.( The option is -l(ell, not one)).

$ split -l 50 bigfile sect

This will split big file into 50 line segments named sectaa,
sectab, secac, and so forth.

In UNIX many new files are created during the course of updating
older files. And if you are not perfect at your file-management duties,
the end result may be a set of files that are similar but contain small
differences as a result of editing and revisions.
UNIX contains several tools that compares files : cmp, comm, diff
and dircmp.

comm Command

Comm command is used to compare two sorted files.

$ sort +1 code > code_out


BOMBAY

CALCUTTA
DELHI
MADRAS
$ sort +1 code1 > code1_out
CHANDIGARH
CALCUTTA

DELHI
GHAZIABAD
$ comm code_out code1_out

66

Chapter 3 : Unix Tools

BOMBAY
CHANDIGARH
MADRAS

GHAZIABAD

CALCUTTA
DELHI

The output of the comm command arrives in three columns: column


1 contains lines unique to the first file, column 2 contains lines
unique to the second file, and column 3 contains lines common in
both the files.
To save the result of comm in a different file is a matter of directing
the output to the file:

$ comm code_out code1_out > new_code

cmp & diff Command

The cmp command compares two files and tells if the files are
different. If they are, cmp reports the first instance of a difference.
Cmp does not report all the differences between the files and it will
report nothing back if the reports are the same. After we sneak a peak
at two files, (using cat command), we can see how cmp works.

$ cat letter1

Dear Rashmi:
Immediately send the information regarding program.
NN
$ cat letter2
Dear Mini:
Immediate send the information regarding program.
Also enclose the return ticket MN.
$ cmp letter1 letter2
letter1 letter2 differ : char 7, line 1

Thus cmp command reports that the two files differ in the sixth
character of the document, located in the line1. Using cmp is the
simplest and quickest way to compare the two files.
On the other hand, the diff command compares two files and tells you
if they are different along with the differences in the lines.

$ diff letter1 letter2


1c1
< Dear Rashmi:
-

Chapter 3 : Unix Tools

67

> Dear Mini:


3c3
< NN

> Also enclose the return ticket MN.


$

Diff command returns more information as compared to cmp


command. Lines beginning with < are found only in the first file, and
the line beginning with > command are found only in the second file.
The dashed line separates two lines that appear in the same place in
the differing files. The numerals indicate exactly where and how
differences occur: 1c1 means that there was a change (c) in the line
(1) of the first file and the line (1) of the second file.
Characters that are deleted from the one version are noted by a d. The
deleted string informs about the string not present in second file but
present in first file. Thus lines in first file must be deleted to make the
files common.

n1,n2dn3
< line n1

< line n2

Informs that the lines from n1 through n2


must be deleted.

n1an2,n3
< line n2

Informs that the lines from n2 through n3


must be appended.

Character a means that a line was appended to a file. The character


a informs that the strings exist in second file and are not present in
first file.

< line n3

dircmp Command

The external dircmp command compares directories. It searches two


directories specified for matching filenames. If a file exists in both the
directories, the two files are compared based on the diff command. A
list is generated indicating if files with same name are identical. If a
file does not appear in both the directories, it is listed as a unique file.

$ ls jet
identity
new
$ ls met
identity
true

68

Chapter 3 : Unix Tools

$ dircmp jet met | uniq


Jun 10 12:41 1996 jet only & met only Page 1
./new
./true

Jun 10 12:41 1996 Comparison of jet met Page 1


directory.
different./identity
$

The first listing jet only & met only states the files and directories
that are only in either jet subdirectory or met subdirectory. If the
names appear in the first column, it means they are in first directory
i.e. jet. If the names appear in second column, it means they are in
second directory only i.e. met.
The second list Comparison of jet met is a comparison of files with
the same name in the jet & met subdirectories. There are three
possibilities in this listing.

directory
different
same

name
name
name

The first signifies the two names are directories. The second states
that the contents of the two files are different. The third states the
contents of the two files are the same.

On a very rudimentary basis, the UNIX commands can be used as


data-base-management tools.

cut Command

Consider the following file:

$ cat rec_emp
RASHMI SYAL
SANJEEV CHAWLA
RICHA VASISTHA
CHARLIE SMITH
AMBICA CHAWLA

100
99
125

114
105

CHANDIGARH
DELHI
LUCKNOW
BOMBAY
CHANDIGARH

284955
235678
873455
746555
234455

The above file can be considered as a database which contains the


names along with their code numbers, city and phone numbers. The
columns are separated by tabs. Database like this are very common
in UNIX.

Chapter 3 : Unix Tools

69

Suppose it is required to create a file, from above database, which


contains the name & city only. This can be done by using cut
command specifying a file for output.

$ cut f1,3 rec_emp > rec_emp.1

Here, the cut command will cut first & third field in the file rec_emp
and send the output to the file rec_emp.1 .
To define the range of fields, say 1,2 and 3, we could use the following
command.

$ cut f1-3 rec_emp > rec_emp.0

If the files are not highly structured (here tabs has been used to
separate the columns) and the fields are separated by another
character say #, we would need to simply specify the character using
-d option:

$ cut -d# f1-3 rec_emp > rec_emp.2

If the space is the character between the fields it will be specified by


enclosing it in single quote.

$ cut -d f1-3 rec_emp > rec_emp.2

If the structure of the files is not that structured, the range of


characters may be specified to cut.

$ -c1-20, 30-40 rec_emp > rec_emp.3

This tells cut to grab first 20 characters in a line, as well as all


characters between 30th and 40th column.

paste Command

Paste command joins together two or more files line by line; that is,
the first line in the second file will be pasted to the first line in the first
file.

$ paste file1 file2 > file.paste

-d option can also be specified to define the separators between the


two fields. Cut & paste command can be effectively used to form new
files or rearrange existing files.

join Command

A better way of merging files, provided that the files contain one
common field, is through the join command. Consider the following
two files to be joined.

$ cut f1,3 rec_emp > rec_emp.1


$ cat rec_emp.1

70

RASHMI SYAL
SANJEEV CHAWLA
RICHA VASISTHA
CHARLIE SMITH

Chapter 3 : Unix Tools

CHANDIGARH
DELHI
LUCKNOW
BOMBAY

AMBICA CHAWLA
CHANDIGARH
$ cut f1,4 rec_emp > rec_emp.2
$ cat rec_emp.2
RASHMI SYAL
284955
SANJEEV CHAWLA
235678
RICHA VASISTHA
873455
CHARLIE SMITH
746555
AMBICA CHAWLA
234455
$ join rec_emp.1 rec_emp.2 > rec_emp.fin
$ cat rec_emp.fin
RASHMI SYAL
CHANDIGARH
SANJEEV CHAWLA
DELHI
RICHA VASISTHA
CHARLIE SMITH
AMBICA CHAWLA

LUCKNOW
BOMBAY
CHANDIGARH

284955
235678
873455
746555
234455

By default the join command will work only when the first field of each
file match and are sorted identically. The files can be joined on the
basis of fields other than the first in each files. The following would
join two files based on the second and fourth column :

$ join -j1 2 -j2 4 rec_emp.4 rec_emp.5 > rec_emp.fin

Here -j option is being used for joining the two files. -j1 2 refers to the
second field of first file and -j2 4 refers to the fourth field of second
file.

Global replacement

There are times when we may want to change repeating parts of a file.
To do so tr command can be used to search and replace the specified
strings.
Suppose the tabs in the file emp_rec are to be replaced by comma(,).
This could be done by the following command:

$ tr <TAB> , < rec_emp

Tr could also be used to change the case of every character in a file.

$ tr [A-Z] [a-z] < file1

The above command will replace all uppercase letters to lowercase


letters.

Chapter 3 : Unix Tools

71

wc Command

The wc command counts the number of lines, words and characters


in a file.

$ wc code
5
15

125

code

The first number is the number of lines in the file. The second number
is the number of words in the file. The third number is the number of
characters. [including new lines] in the file. Finally, we displays the
name of the file it found.
We can have three options 1]

-l option

means that only lines are to be counted.

3]

-c option

means characters are the only things to be


counted.

2]

-w option

$ wc - lc code
5
$

125

means only counting words

code

It counts the number of lines and characters in code file.

spell Command

UNIX spell can be used to check the spellings in the file. Spell is
intended to work with UNIX pipes and input redirection, so spell
supports a very primitive interface. But the limitation in the spell is
that it can tell the word which is misspelled, but offers no suggestions
for the proper spelling. The syntax of the spell command is as
follows:

$ spell filename

Spell will then examine all the words in the given file and print out
a sorted list of all the words spell flagged as errors. Its upto you to
search for these files in the original file and make corrections, using
the text editor (vi or emacs).

strings Command

Cat command can be used to view the file contents, which has been
discussed earlier. However, cat command is limited to display the

72

Chapter 3 : Unix Tools

ASCII characters. There may be times when non-ASCII files are to be


displayed. In such cases, strings command can be used to display
the file contents in a format you can handle. The following command
line displays the file named program.

$ strings program

Chapter 3 : Unix Tools

73

UNIX provides hundreds of powerful tools for working with


text files and other aspects of your system.

The grep command and its brethren fgrep and egrep search
text files for words and phrases. Grep searches for text in
either single file or any number of files you specify. It goes
through the file and returns the lines containing your specified
text. The text can be single word or a string surrounded by
quotation marks. The basic syntax for the grep command is
$ grep phrases to look for filename_to_search

The egrep command goes further and searches for the


multiple strings. The fgrep command is similar to egrep
command but the text is written in different lines.

Sort in a utility program which sorts the contents of a file into


alphabetic or numeric order. There are many options which
control the sort order. This command also merges files that
are already sorted, and checks files to determine if they have
been sorted
split command will split a file into pieces. This command is
useful to split big files which are too large to fit in the help of
editors.

Files can be compared by using any of the cmp, comm, diff,


and dircmp.
To extract data from files and insert the data into other files,
you can use the commands cut, paste and join.

To make global replacement in the file tr command can be


used, whereas to count number of lines, words, & characters
wc command can be used. spell command can be used to
check the spellings. The UNIX doesnt provides the option to
change the correct spelling through spell command. To view
Non-ASCII characters strings command can be used.

74

Chapter 3 : Unix Tools


1.
2.

3.

a.

What does the diff command do?

c.

Explain the command diff - file2.

b.

a.

What is the function of the dircmp command?

c.

What command makes the output listing easier to


read on your screen?

b.

a.
b.
c.

4.

5.

6.

How do you make diff ignore blanks in the input?


Explain the output of the first listing generated by
dircmp.

Why might you use the fgrep command instead of


grep?

How do you search for uppercase and lowercase letters


simultaneously?
What option prevents diagnostic messages from being
displayed?

a.

What is the function of the egrep command?

c.

How do you display lines that do not match the given


string?

b.

In What situation if no argument are given on the env


command line?

a.

What does the find command do?

c.

Write the command to remove all files which have not


been modified in 30 days, starting at the current
directory.

b.

Write the command to display all the files in your


HOME directory and all subdirectories.

a.

What type of files does the sort command sort?

c.

How do you sort numbers?

b.
d.
e.

Write the command to sort on filed 5.

Can sort reverse the order of the sort?

How do you remove duplicate adjacent lines?

Chapter 4
REDIRECTING OUTPUT
STANDARD FILES
REDIRECTING THE STANDARD OUTPUT
PIPES

76

Chapter 4 : Redirecting Output


UNIX commands (programs) have three standard files.
1.

STANDARD INPUT-

2.

STANDARD OUTPUT -

3.

DIAGNOSTIC OUTPUT - The file to which program writes


any error responses.

The place from which a program


expects to read input.

The file to which program write its


results

Generally the standard input for command is taken to be users


terminal keyboard. Standard output and diagnostic output goes to
users terminal screen. But we can always change these default
settings and tell the standard input for a command is to be taken from
a file and standard output of a command written to a file. This process
is called redirecting Input & output.

> character is used to redirect the standard output of a command and


the result of the command will be stored in the file which is specified
and it will not display the results of commands on screen.

$ ls -l > contents
$

This will store listing of current working directory in a file called


contents and no listing will be displayed on screen. When shell see the
redirection mark ( >) , it creates an empty file to hold the results of
command. But if the file already exists, it will display an error, saying
that the file already exists.

$ cat contents

Now you can see the contents file, which will have the output of ls l command. In this output, it will display the name of contents file
also but the file size will be zero. The reason for this is that it is the
shell which creates the file to receive the commands output, and it
does this before the command runs.

APPENDING STANDARD OUTPUT TO A FILE

>> character can append the output of command to the end of an


existing file.

$ pwd >> contents

This will add the name of current working directory at the end of file
contents.

But if you append a file which does not exist , then this command will
display a message saying that the file does not exist.

Chapter 4 : Redirecting Output

REDIRECTING THE STANDARD INPUT

77

Generally, redirecting input is not used as often as redirecting


output, because most commands are designed to take their input
from files anyway. For redirection the standard input < character is
used.

$ cat < contents

This command displays the contents of file Contents to the standard


output. Basically cat command does not require this redirection
marker and without this market also it gives the same effect as above
$ cat contents, but the cat with redirection input is considered as a
single step process, where as the other is considered as two-step
process.
The input/output tools can be used in conjunction with any commands,
programs, or arguments. The standard input/output command can
also be used in the single command.

$ command < infilename > outfilename

It must be noted that any command employing standard input/


output must begin with a command.
The following table lists the details of all redirection command:

Symbol

Usage

>

command > filename

<

command < filename

>>

command >> filename

command1 | command2

Result

Output of command is sent


to filename
Input from the filename is
used by the command.
Output of the command is
appended to filename.
Run command1, then send
the output to command2

The notion of pipes takes the notion of input/output a step further.


It is also an area of particular interest to programmers, since the idea
of pipes plays a large role in UNIX programming.

Standard input of a command can be taken directly from the standard


output of another command , and similarly standard output of one
command can be directed straight to the standard Input of next
command. This feature is called piping, and a string of commands
hooked together in this way is called a pipeline. The symbol for a pipe
is vertical bar [ | ]. Usage of pipe command is as follows :

$ command1 | command2

78

Longer pipe commands

Chapter 4 : Redirecting Output

The shell prescribes no limits on the number of pipelines in a


command line. A pipeline like following would be acceptable.

$ ls *.c | grep arg | lp

The above command searches for all files ending in .c in the current
subdirectory, searches these files for the string arg, and then prints
all the lines containing arg.
Although there is no limit on the number of pipelines, longer
pipelines can be confusing and harder to identify. The shell allows to
divide a long pipeline into several easier to read components. The
previous command could be written as follows.

$ ls *.c |
> grep arg |
> lp

Here, > sign tells that shell is waiting for additional input from the
user. The > is a secondary prompt, or PS2. Since the initial command
ended with a pipeline command, the shell correctly assumes that
there is more input coming, otherwise, you would be generating an
error with the incorrect use of pipe command.
The shell also uses standard input and output to send you error
messages, technically speaking, they are known in UNIX parlance as
standard error. Standard error is sent to screen by default - the most
logical place for it.
Error messages can generate under a variety of circumstances. Since
the default with most UNIX commands is sending output to your
screen, it makes sense that all error messages related to the command
are sent to your screen. However, the shell goes a step further and
sends all error messages to the screen, even those related to the file
operations that dont normally generate any response. Consider the
above example, with no .c files available in the present working
directory:

$ ls *.c | grep arg | lp


ls : *.c not found

Without this response, youd never know exactly why the command
failed.

However, there may be times when it is required to redirect the error


messages to a file. This can be done by slightly expanding the
command line. To do so the redirection symbols discussed earlier can
be used but they must be preceded by 2.

$ ls *.c | grep arg | lp 2> smediaerror

This will redirect the error message to the file smediaerror.

Chapter 4 : Redirecting Output

79

UNIX provides the facility to redirect input or output of UNIX


commands to other devices than the standard one. The
redirection operators are <, >, and >>.

The < operator redirects the input for a command to come


from a given file.

$ command < inputfile

The > operator redirects the output of a command to the end


of the file:

The >> operator appends the output of a command to the end


of a file:

$ command > outputfile

$ command >> outputfile

The pipe symbol can be used to pipe together two commands,


which means that the output of the first command becomes
the input of the second command.

$ command1 | command2

Use an ampersand(&) at the end of the command line to run


the command in the background.

80

Chapter 4 : Redirecting Output


1.

What are three standard types of I/O?

3.

Write the command to redirect the standard output to a file.

2.
4.

Write the command to force the standard error onto standard


output.
State True or False
a)

b)
c)

d)
e)

The VDU is the standard output unit for all UNIX


commands.
The output can be redirected to printer and file.
UNIX cant receive the input from a text file.

>> symbol is used to add the output of a UNIX command


to existing text file.

The output of a UNIX command can be added in the


middle of an existing text file.

Chapter 5
COMMUNICATION IN UNIX
COMMUNICATION & ELECTRONIC MAIL
CONTROLLING MESSAGES
THE PAPER-FILLED OFFICE
SENDING MAIL
RECEIVING MAIL
THE INTERNET
CREATING MAIL
HANDLING MESSAGES
SAVING MESSAGES

82

Chapter 5 : Communication in Unix


UNIX provides facilities for exchange of information between users
on the same system. The main UNIX system features which facilities
communication has been described below:

SENDING MESSAGES TO OTHER USER


write Command

The write command opens a line of communication to send messages


to other users on the system in real time means that the write
command sends a message to a specified user right at the time when
you type the message, provided that the other user is logged in to the
system. For another user to receive a message-

that user must be logged in

user must not have refused message permission.

When a message is sent to a user who is not logged in, the message
user not logged in appears. If the message is sent to a user who has
refused message permission by setting mesg command to yes, the
message permission denied appears.

a)

To write a message to user mack from user smedia who is


logged in enter:

$ write mack

Press the enter key and type the message -

I need to see you ! Meet me in the computer room at 12.30.

Then press the Ctrl-D key sequence to terminate the write


command mode. If smedia is using terminal trem/02, macks
terminal displays
b)

Message from smedia term/02


3
Aug13 12:00:00......
I need to see you ! Meet me in the computer room at 12.30.

To hold a conversation with this command enter

$ write mack
Press the enter key and type,

Meet me in the computer room at 12:30


O

This O starts the conversation. The O at the beginning of next


line means the message is over. It tells mack that smedia is
waiting for a response. (Ctrl-D is not to be pressed). Now mack
replies by typing.

$ write smedia
I am running tests at 12.30 can we meet at 3?
O
And smedia might respond:

Chapter 5 : Communication in Unix

OK The computer room at 3,


O-O

c)

83

Here O-O means over and out, telling mack that he has
nothing move to say. If
mack is also finished O-O, then
both can press Ctrl-D to end the conversation.

Long messages can also be sent by putting the computer


message in a file and then redirecting that file as input to the
write command. For this enter:

$ write mack < message.text

So here instead of taking the standard input from keyboard,


it takes the input from message.text and redirects the standard
input.

mesg Command

mesg command permits or refuses write messages it controls whether


other users on the system can send messages to you with write
command or not. This command is required when user does not want
to get interrupted by others.

a)

$ mesg n
$

The n(no) tells the system that user do not want to be


interrupted. If anyone tries to write to this user, they will get
the message -

b)
c)

Permission denied.
$ mesg y

The y (yes) allows messages to come through again.

To display what your current message - permission setting is,


enter:

$ mesg
is y

Means messages are enabled and can come through to this


users.

Computer cynics like to point back to several predictions made in the


1950s and 1960s regarding the office of the 1990s. Filing cabinets
and typewriters would be obsolete by 2000 because the office of
tomorrow would be paperless: all document delivery and storage
would be done electronically.

As you can tell by looking at the pile of papers, faxes, and folders
strewn across your desk, the day of the paperless office hasnt yet

84

Chapter 5 : Communication in Unix

arrived. We still commit most of our work to paper backups (which we


can consider nonvolatile storage devices), while truly important
papers are never exchanged in electronic form. Indeed, the world uses
more paper now than at any other time in the past.
The cynics miss the point, though: if we truly wanted a paperless
office we could eliminate most office paper usage in a short amount
of time. Only because of factors outside the technology realm( legal
reasons to maintain paper versions; cultural aversion to dependence
on computers) does the business world avoid a total conversion to the
paperless office. The tools are all in place, especially in the UNIX
world. Powerful and affordable computers that can display graphics
images, networks that can shuffle huge documents and databases
instantaneously, high performance laser printers and easy-to use
electronics mail.

The mail program has been an important part of UNIX almost since
the very beginning. As UNIX evolved, so has mail- to an extent. The
actual electronic-mail mechanisms are similar to the original mail
mechanisms: changes mainly concern how a user interacts with a
mail program. The procedures described here may not appear exactly
the same on your system, as there are a large number of mail
programs, both UNIX and XWindows -based that vary in how they
present information to the user.

mail is the UNIX facility where users can send messages to each
other, such that the messages get collected in a mailbox somewhere
in the system.

Unlike the write command, which interrupts user to display the


message on the screen, mail waits until user have finished what he
is doing before telling that there is mail waiting. To send the mail to
a user it is not necessary that user to be currently logged in and in
this case, the mail remains in the mail box file, and user is notified
of mail when he logs in.
So there can be two cases when mail is sent

1-

When the user in logged in

In this case system informs user of waiting mail at two


different times, if required.
a)

b)

First at the time , when mail arrives while user is using


UNIX commands. After he finished whatever he is
doing, he gets the message of mail.

You have mail

If at this time user does not read the mail , user will get
the same message

You have mail

Chapter 5 : Communication in Unix


2-

85

again and again at the time of log in until he reads the


message.
When the user is not logged in, only (b)case in applicable,
because mail is send when user is not working on anything so
their is no question of (a) case.

The mail command operates on two types of mailboxes

System mailbox

Personal maibox.

Each user on a system is assigned a system mailbox. A users system


mailbox is a file located in the /var/spool/mail/username. For
example, for user smedia, system mailbox is /var/spool/ mail/
smedia. The system mailbox contains mail that a user has received
but has not read, deleted or saved to a file.

In addition to the system mailbox, each user is assigned a personal


mailbox. By default the personal mailbox is the /home/username/
mbox. For ex. for user smedia, the /home/smedia/mbox file is the
personal maibox . When user views mail in system mailbox, all
messages which have been read but not deleted or saved are put in
users personal mailbox.

As discussed earlier in the chapter, UNIX informs you of incoming


mail when you login the system. Youll see a message something like
this :

$ mail
mail version 4.0 Type ? for help.
2 messages:

2 [email protected] Sun Jul 18 2:45 11/274 Stuff


1 erc Thu Jul 16 21:25 11/274 Hello

The shell responds with a list of your mail messages, listed in the
order that they were received by your system, newest mail first. (
These messages are usually contained in the file /user/mail/
yourname, /usr/spool/mail/yourname, or /usr/spool/meuque/
yourname.).The first field lists the sender of the message, the second
through fifth fields denotes the time and date the message was
received, the sixth field records the number of lines in the message
and the size of the message ( in bytes), and the final field indicates the
subject of the message.
Press Enter to read the first message on the list. If its a long
message, the entire message will scroll by. If you want to stop
scrolling the message, type Ctrl-S to start it again, type Ctrl-Q. There
are two types of messages waiting for us:

a message from [email protected] and

86

a message from erc.

Chapter 5 : Communication in Unix

Your electronic mail can come from two sources - Your own system
and from other systems.

Mail from other system, sent on Internet or Usenet, has its own
addressing scheme (more on that in the next section). Mail from your
own system uses the same login names as described earlier in the
chapter. These names are contained in the /etc/passwd file.
First we will concentrate on the mail sending & receiving from your
own system.

a)

To send mail from smedia to mack, type

$ mail mack
Hi, How are you?
I have brought the two tickets for movie if you are free,
we will meet in evening to discuss the program in detail
^D
$

b)

Here also, like the write command, message is typed and


ended with ^D command.
To send mail to more than one user, type

$ mail mack sally

c)

and then the message is typed and will be send to both mack
and sally.

To send a file to another user, enter the following command at


the prompt -

$ mail mack < letter1

d)

In this the file letter1 is sent to user mack.

$ mail mack
Inform me about your evening program
^D
Mail : Cant send to mack
Mail saved in dead.letter
$

If you
or by
saved
again

try to send mail to someone who is not a user of system


mistake wrong username is typed, then message is
in dead letter file by default and which can be send
and you dont need to type the whole message again.

$ mail mack < dead.letter

Chapter 5 : Communication in Unix

e)

$ rm dead.letter
$

87

To read the mail or to know, whether a user has received any


mail or not, type

$ mail

No mail for smedia


$

Means there is no mail for smedia But if smedia has some mail
, then if you type mail

$ mail
from mack wed jun 11 12:30 1995

Means a list of message in your system mailbox is displayed.


The list is followed by the mailbox prompt (& ) to indicate
waiting for input. When this prompt is displayed, enter any
mailbox sub-command. To see a list of sub-commands, enter:

f)

A list of Mail sub-commands is displayed .

To look at the contents of your personal mailbox, enter the


following at the prompt:

$ mail - f

The Internet is the most extensive computer communications network


in the world. Many corporations, universities, and research institutions
send and receive mail via the Internet. Not all of the computers on the
Internet run the UNIX operating system (everything from Grays to
UNIX and MS-DOS-based pcs. are represented) but most share two
basic addressing scheme.

The first and older scheme is called a bang pabb, first popularized on
the Usenet, which makes up part of the internet. Essentially youre
telling the mail system the exact route it must take to send you mail
. This can be a gigantic pain, especially if there are many machines
a message must go through before it is delivered. Luckily this manual
addressing of electronic mail is on the wane, which is why you see so
few electronic- mail addresses dotted with exclamation marks.
Still, theres a need for bang paths when it comes to electronic mail.
Many users now take advantage of gateway, which forward mail to
other connected machines. If you have access to a gateway (check
with your system administrator; chances are that you do if you have
the ability to send and receive electronic mail from the internet), you
can just send mail to the gateway, denoting the system name and the
user name:

$ mail unnet\!concubine\!kevin

88

Chapter 5 : Communication in Unix

Where unnet is the name of the gateway ( as it happens, unnet is a


very popular gateway), the system name is concubine, and kevin is
the user name, the bang character, or exclamation point (!), separates
the entries. If you use the C shell, the bang character has special
meaning ( it is used for the list of previous commands the command
history). Thus you ll have to use the backslash character to escape
the bangs:

$ mail unnet\!concubine\!kevin

The previous command tells the C shell that you really means to use
the exclamation mark (!) and dont want csh to look in its record of
your previous commands.

The newer addressing scheme, and one that is growing in popularity


(mainly because of the growing popularity of the internet), is called
domain addressing. Structured as the exact opposite of a bang path,
a domain address couples the name of the user with an address. This
scheme grew out of the need for international standardization of
electronic-mail addresses and provides a hierarchical structure to
addressing. Essentially, the world is split into country domains,
which are then divided into educational domains (indicated by the
suffix, .edu in the address), commercial domains ( indicated by the
suffix .com in the address), government domains (.gov), and more
.There are hundreds and hundreds of domains, with the number
growing each day.
Reading a domain address is quite simple, in the address of :

[email protected]

rahul refers to the user, while mr.net refers to the domain. The user
and domain names are separated by the at @ symbol. As a user, you
dont need to know the specific path a message must take, nor do not
need to know the name of a gateway. With a domain address, sending
a message is simple.

$ mail [email protected].

The idea of the internet is fairly amorphous and abstract (You didnt
think we could make it through a chapter without a little abstraction,
did you?). The internet is technically a collection of many networks
that somehow manage to talk to each other. As a user, all you need
to know is a recipients electronic mail address; the system
administrator handles the basic details of linking a system to the
internet.

To create mail for the other systems the method is similar as


discussed earlier. To create a short message at the keyboard, simply
combine mail with the name of the recipient:

$ mail [email protected]

Chapter 5 : Communication in Unix

Hi, How are you?


I have brought the two tickets for movie if you are free,
we will meet in evening to discuss the program in detail
^D

89

As always, end input from the keyboard by typing Ctrl-D. Some Email programs also accept a single period on its own line to terminate
the message, instead of Ctrl-D. The procedure would be the same if
you were sending a message to a user on a remote machine.
You can send the same message to multiple users with the -t option:

$ mail - t [email protected] [email protected]


This, too, is a test.
^D
$

The resulting message will contain multiple To: fields in the header.

Sending an existing file as the text of an Electronic-mail message is


also similar. After creating an ASCII file using vi or emacs, save the
file and then redirect it as input on the command line:

$ mail [email protected] < note

where note is the name of the file

The Berkeley UNIX mailx program allows you to call up a text editor
from within mailx, by using the ~v command. You must start this
command on its own line.

$ mailx kevin
~v

Unless youve configured your system differently, the default text


editor will be vi. Edit your message using the vi commands and then
exit vi with the ZZ (save and exit) command . You will then be back
in the mailx program, where a single period on a line of its own ends
the message.
System V Release 4 users can send binary files (such as program) as
mail messages with the -m option.

$ mail - m binary file [email protected]

Where binaryfile is the name of the binary file you wish to send. The
resulting message will have a line in the header signifying that the file
is binary.

90

Chapter 5 : Communication in Unix


After you read a message, the shell presents you with a different
prompt:

Asking for a response related to the mail program. There are many
actions that you can take at this point: the handiest options are listed
in following table
Command

Result

Prints previous messages

RETURN
df

dN
dp
dq

uN

s filename
w filemane
?

Prints next message

Deletes current message.

Deletes message number N.

Deletes current message and goes to the


next message.
Deletes current message and quits
Undeletes message N.

Saves message to filename. If filenames is


not specified , message is save to $HOME/
mbox.
Saves message without header information
to filename. If filename is not specified,
message is saved to $HOME/ mbox.
Lists mail commands

As we see in the above table, saving a message is simply a matter of


typing.

?s

If we dont specify a filename, the message is saved to $HOME/mbox.


If you dont get many messages, its no big deal to save them all to the
same file, but if you get a lot of messages on a wide variety of topics,
its a good idea to introduce some organization to your mail habits.

Lets say youre working on a project with user smedia, and you want
to keep all of his mail message in the same file. You do so with the s
option at the prompt.

? s smediamail

Where smediamail is the name of the file containing his mail messages.
When you do this the first time, the shell creates a file named
smediamail. Subsequent uses will append mail messages to the
existing smediamail file. To read this file, use mail with the -f option:

$ mail -f smediamail

Chapter 5 : Communication in Unix

91

UNIX provides facilities for exchange of information, between


users on the same system, with each other electronically
either directly using write command or indirectly via mail
command.
The write command opens a line of communication to send
messages to other users on the system in real time means that
the write command sends a message to a specified user right
at the time when you type the message
mesg command permits or refuses write messages it controls
whether other users on the system can send messages to you
with write command or not.
Electronic mail forms a politically correct, environmentally
sound, and very useful business communication tool.

The mail program is your standard, if primitive, means to


access your electronic mail, just type mail at shell prompt.
mail is the UNIX facility where users can send messages to
each other, such that the messages get collected in a mailbox
somewhere in the system.
mail

Youll see a list of new messages.

To send mail, type mail username, where username is the


name of the recipient, at the shell prompt.

$ mail smedia
Subject : test
Appear in the test.
^D
$

The input must be ended from the keyboard by typing Ctrl-D.

92

Chapter 5 : Communication in Unix


1.

a.

What is the purpose of the mail command?

c.

What is the format for reading mail from your mbox


file?

b.

d.
e.
f.
g.

What is the format of the mail command to send mail


to a user?
How do you edit a message you are sending?

When reading mail how do you display the next page


of header lines?
When reading mail how do you delete messages 20
through 34?
Write the internal command to send message 5 to the
dmp printer.

2.

a.

What is the purpose of the mesg command?

3.

a.

What does write command do?

4.

State True or False.

b.
b.
a)

b)
c)

d)
e)

Write the command to prevent message?

How do you terminate the write command to send the


messages.
write command doesnt permit conversation.

The mail messages are usually contained in /usr/


mail/yourname.
Domain addressing is the newer addressing scheme.

dN is used to delete nth number line in the message.

In domain addressing the user name & the domain are


separated by #.

Chapter 6
TEXT PROCESSING
TEXT EDITOR VI & TEXT PROCESSING
VI EDITING MODES
MOVING WITHIN A FILE
CHANGING TEXT
SAVING CHANGES TO A FILE

94

Chapter 6 : Text Processing


An editor is a utility program that is used to make modifications to the
content of a file. An editor is designed to deal with files containing
strings of characters in a particular character set. Usually an editor
is an interactive utility means whatever changes are made by the
user, that can be viewed at that time.

Vi editor is started by specifying the name of the file or files to be


edited since the vi editor is a full-screen editor, so text can be edited
on a screen- by- screen basis. The vi editor makes a copy of the file
which is being edited in an edit buffer , and the contents of the file are
not changed until the changes are saved. The position of the cursor
on display screen indicates its position within the file, and the subcommands affect the file at the cursor position.

The vi editor operates in the following modes:

Command Mode

When the vi editor is started, it is in command mode. Any subcommand


is entered except those designated for use only in the text input mode.
The vi editor returns to command when subcommands and other
modes end. ESC key is pressed to cancel a partial subcommand.

Text input mode

This mode is used when text is added. Text input mode is entered with
any of the following subcom mands - the a subc omm a nd , A
subcommand, i subcommand, I subcommand , o subcommand, O
subcommand, C subcommand, s and S subcommand, R subcommand.
After entering one of these subcommands, text can be entered into the
editing buffer. To return to command mode, ESC key is pressed for
normal exit or Ctrl-C to end abnormally.

Last line mode

Subcommands with the prefix :(colon), /(Slash), ? (question mark), !


(exclamation point) or !! read input on a line displayed at the bottom
of the screen , when initial character is entered, the vi editor places
the cursor at the bottom of the screen, where remaining characters of
the commands are entered. Enter key is pressed to run the
subcommand or Interrupt (Ctrl-C) key to cancel it.

CALLING UP VI EDITOR

Vi editor is called up by -

$ vi textfile.

Chapter 6 : Text Processing

95

After typing this, a file is read into the edit buffer, the terminal screen
is cleared, the window is set at the first line of buffer, and cursor is
initially set at the first character of first line in the window.

Moving within a line

Following commands are entered in command mode. A incomplete


command can be cancelled by pressing ESC key.
Left arrow () or h

Moves the cursor one character to the left

Up arrow () or k

Moves the cursor up one line while it


remains in the same column.

Down arrow () or j

Right arrow () or l

Moves the cursor down one line while it


remains in the same column.
Moves the cursor one character to the
right.

Moving within a line by character position

Following subcommands are entered in command mode and an


incomplete command can be cancelled by pressing ESC key.
\^

Moves the cursor to the first nonblank character

Moves the cursor to the end of the line.

fx
Fx
tx
Tx
;
,

Moving to Words

Moves the cursor to the beginning of the line.

Moves the cursor to the next x character or any


other character which can be specified in place of
x.
Moves the cursor to last x character or any other
character.

Moves the cursor to one column before the next x


characters any other character.
Moves the cursor to one column after

Repeats the last f, F, t, or T in same direction.

Repeats the last f,F, t,or T subcommand in the


opposite direction.

Following subcommands are entered in command mode:


w

Moves the cursor to the next small word

Moves the cursor to the next end of a small word.,

W
B
E

Moves the cursor to the previous small word.


Moves the cursor to the next big word

Moves the cursor to the previous big word.

Moves the cursor to the next end of a big word.

96

Moving by line position

Chapter 6 : Text Processing

Following subcommands are entered in command mode:


H

Moves the cursor to the top line on the screen

Moves the cursor to the middle line on the screen,.

Moves the cursor to the last line on the screen.

Moving to Sentences, Paragraphs or Sections

Following subcommands are entered in command mode. An incomplete


subcommand can be cancelled by pressing the ESC key.
(
)
{
}

Places the cursor at the beginning of previous


sentence.

Places the cursor at the beginning of the next


sentence.
Places the cursor at the beginning of the previous
paragraph.
Place the cursor at the beginning of next paragraph.

Moving By Redrawing the Screen

These are the commands of command mode and an incomplete


command can be cancelled by ESC key.
z

Z
z.

Redraws the screen with the current line at the top


of the screen.
Redraws the screen with the current line at the
bottom of the screen.
Redraws the screen with the current line at the
center of the screen.

Paging and Scrolling

Following are the commands of command mode. An incomplete sub


command can be cancelled by pressing.
Ctrl-U

Scrolls up one- half screen.

Ctrl-F

Scrolls forward one screen.

Ctrl-D
Ctrl-B
Ctrl-E

Ctrl-C
Z+

Z\^

Scrolls down one - half screen.


Scrolls backward one screen.

Scrolls the window down one line.


Scrolls the window up one line.
Pages up

Pages down.

Searching For patterns

Following Sub commands are entered in command mode. And an


incomplete command can be cancelled by ESC key.

Chapter 6 : Text Processing


[Number]G
/Pattern
?Pattern
n
N

97

Places the cursor at line number or at the


last line if number is not specified.
Places the cursor at the next line containing
the character string specified by the Pattern
parameter.

Places the cursor at the next previous line


containing the character string specified
by the pattern parameter.
Repeats the last search for the specified
pattern in the same direction.
Repeats the last search for the specified
pattern in the opposite direction.

ADDING TEXT TO A FILE [TEXT INPUT MODE]

Following subcommands are used in command mode to change the vi


editor into text input mode.
a Text

A text
i text
I Text

If you type a followed by the text which is


to be inserted, it inserts the text after the
cursor. Text input mode can be ended by
pressing ESC key and whatever is typed,
will come on screen.
It adds text specified by the text parameter
to the end of the line. Text input mode can
be ended by pressing ESC key.

I t i n s e r t s t e xt s p e c i f i e d b y t h e t e x t
parameter before the cursor. Text input
mode can be ended by pressing ESC key.
I t in se r ts t e xt s pe cif ie d b y th e Tex t
parameter before the first nonblank
character in line and to stop text entry ESC
key is pressed.

It adds an empty line below the current


line. Text input mode can be ended by
pressing ESC.

It adds an empty line above the current


line. Text input mode can be ended by
pressing ESC key.

[Text Input Mode]

Following commands can only be used in text input mode. These


commands have different meanings in command mode.
Ctrl-H

Erases the last character.

ESC

Interrupts and returns to command state.

Ctrl-W

Erases the last small word.

98

Command Mode

Chapter 6 : Text Processing

Changes the rest of the line.

CW

Changes a word.

CC

CW Text
D

dd

dw
J

rx
R text
s

<<
>>
\^

Changes a line.

Changes a word to the text specified by text


parameter.
Deletes the rest of the line.
deletes a line.
Delete a word
It joint lines

Replaces the current character with the


character specified by x

Overwrites characters with the text


specified by text parameter.
Substitutes character.

Substitutes lines [same as CC]

Shifts one lines from cursor to the end of


the screen to the left.
Shift one line to the right.

Changes letter at the cursor to the opposite


case.

COPYING & MOVING TEXT

Following commands are entered in command mode. An incomplete


subcommand can be cancelled by pressing the ESC key.
p

P
xp
xd
y

xy
y

Puts back text from the undo buffer after


the cursor.

Puts back text from the undo buffer before


the cursor.
Puts backtext from the x buffer.

Deletes the text into the x buffer.

Places the object that follows [for example,


w for word] into the undo buffer.

Places the object that follows into the x


buffer, where x is any letter.
Places the line in the undo buffer.

RESTORING AND REPEATING CHANGES


u

Undo the last change. If cursor is moved


away from the position at which the change
is made, the cursor is repositioned to its
original places after the change has been
done. u command does not undo the
change before the last one: it undoes the

Chapter 6 : Text Processing


U

:W
:W file

EDITING A SECOND FILE

99

original undo command, thus applying


the change all over again.

Restores the current line if the cursor has


not left the line since the last change. It
can undo several changes, but only those
made on the same line. If cursor is moved
away from that line, U does not do anything.
U will not do undo itself, so typing a second
U has no effect.
Repeats the last change : While u says
undo that which I just did, says do it
again. Regardless of the changes made,
whether it changed a word, added a new
sentence, or deleted two lines, if cursor
position is changed and . is used, same
changes will be done at the new position.
This com m and wr ites the ed it b uf fer
contents to the original file.
Writes the file specified by the file parameter
with the edit buffer contents.

:e file

Edits the specified file.

:e + file

Edits the specified file starting at the end.

:C # or Ctrl -A

Edits the alternate file. The alternate file is


usually the previous file name before
accusing another file with a:e command.
However, if changes are pending on the
current file when a new file is called, the
new file becomes the alternate file.

:e !

Reedits the current file and discards all


changes.

:e + Number file: Edits the specified file starting at the


specified line number.

FINDING OUT FILE INFORMATION


Ctrl-G

Shows the current file name, current line


number, number of lines in the file, and
percentage of the way. Through the file
where the cursor in located.

INTERRUPTING & ENDING VI EDITOR


zz
:q

Exits the vi editor, after saving changes.

Quits the vi editor. If you have changed the


contents of the editing buffer, the vi editor

100

Chapter 6 : Text Processing

:q!
ESC
Ctrl-?

displays a warning message and does not


quit.
Quits the vi editor, discarding the editing
buffer.

Ends text input or ends an incomplete


subcommand.
Interrupts a sub command.

ACCESSING UNIX COMMANDS FROM WITHIN VI

If you want to run a UNIX command from within vi, by typing the
usual colon[:], followed by an exclamation mark [!] followed by
command which you want to run.
If there are several such commands in a row, it in better to enter the
shell from vi. This can be done by typing either : sh or just : sh. At
this point, you can see the system prompt [$] and many commands
can be executed.
When you want to return to vi session, it can be done by typing CtrlD, and you will come back to vi session at the same point in the file
as you left it.

TEXT PROCESSING

Text Editing Versus Text Processing

The traditional UNIX world makes a distinction between text editors


and text processors. On a base level, both appear to do the same
thing, create and print text files. The similarity ends there, however,
as a text editor is geared more for internal use, while a text processor
introduces formatting features that stiff up documents intended for
the outside world. A text editor allows you to designate characters as
bold or italics, but a text processor actually carries out these
commands.

Troff: What You See isnt Quit What You Get

One of the most popular publishing software in the world, troff and
its pre-deccessors are essential tools for any UNIX user who wants to
create professional -looking documents and dont want to shell extra
for a professional package. These tools come with most versions of
UNIX although sometimes theyre split out into a package called the
Documents Workbench.

To understand troff, its important to review its history. The product


we call troff began life in 1964 as runoff and ported to UNIX in the
form of roff, used to supply simple formatting to documents printer.
Roff was revised in 1973, as nroff was created to add more
formatting capabilities. Noroff didnt have a long life as the latest and
greatest; it was extended that same year to support a typesetting
machine and renamed ditroff Finally, troff was revised to support
virtually every printer and renamed ditroff (for device-independent

Chapter 6 : Text Processing

101

troff). Todays we refer to troff almost exclusively, even through its


most likely were actually using ditroff.

In this day of graphical-user interfaces and WYSIWYG computing,


troff is a throwback to the days of Wordstar and more abstract (a-ha!)
computing tools, when you had to visualize your final output and
provide commands to the system on how to achieve this final output.
Today we can highlight text and change its formatting from bold to
italic through a simple menu choice, if were using a word processor
that supports a WYSIWYG mode.

Creating a Troff Document

Troff is like a word processor where you can input text and then
manipulate it. In the true UNIX tradition of dividing processing tasks
to free the user from too much interactively with the system, you
create a text document in a text editor like vi or emacs insert the
proper formatting commands there, and then run your formatted
document through troff.
The best way to explain troff is to look at before-and-after as shown
below.

Our originating document is a standard memo, with several formatting


commands that begin with a backslash(\) or a period(.) Troff then
interprets these commands to something the output device can
understand; the end result looks like the shown on the previous page.
When you run troff you must specify the destination of its output;
without such specification, the default output is the screen;

$ troff test

Or, better yet, go ahead and redirect the output of troff a file.

$ troff test > test.tr

We can read the formatted file using cat:

$ cat test.tr

If system has a printer connected, go ahead and print the result of the
troff command. Use troff and then redirect the output to the printer:

$ troff -printer test ! lp

USEFUL TROFF COMMANDS


Command Result
.ad

Turn off text justification.

.ce n

Center next n lines. If no number is


specified, only the following line will be
centered.

.bp

.fi

.ft n

Page break.

Tells troff to fill lines of text.


Change font to n.

102

Chapter 6 : Text Processing

\fn

Change font to n.

.ls n

Sets the line spacing on a document ls 2


would cha nge the spacing to doub lespaced. The default is single-spaced.

.in n

.na
.nf

.pl n

.po ni

.ps n
\Sn

.sp n
.ti n
.un n

Indent the following lines by n spaces.

Turn on text justification.

Tells troff not to fill lines of text.

Sets the number of lines on the page to n.


The default is 66 lines to a page. Note that
laser printers usually have a smaller
number of lines per page.

Sets the left margin; po 1l would set the left


margin to 1 inch. its essential that you set
this, because the default has text appearing
all the way to the left of the page.
Change the point size to n.
Change the point size to n.

Sets the number of lines to skip by n. To


skip a specific amount, use ni for inches or
nc for centimeters.
I ndent th e first lin e of the f ollowin g
paragraph n spaces.

Underline entire following line. If a number


is specified, then n lines will be underlined.
Must be used with entire lines.

Chapter 6 : Text Processing

103

Unix uses text files for just about everything, including most
system configurations. To edit these text files, we cover the
two most commonly used text editors under UNIX: vi and
emacs. These editors allow you to create, modify, and view
text files. Vi was hot technology in the 1970s but shows its age
today. Yet, as a new user, youll have more luck with vi.
You can select from many brands of commercial word
processors that provide WYSIWYG what -you see-is-whatyou-get computing, even through this chapter concentrates
on a set of typesetting tools that definitely doesnt provide any
form of WYSIWYG.

You start with original text files created with any text editor,
such as vi or emacs. You then feed these files of troff, or the
related nroff or ditroff. Troff translates dot commands in text
file and output formatted text.
Some of these dot command include .ad to run off text
justification, and .ce which center lines of text. To speed your
work with troff, you can use a set of prebuilt macros, such as
the memoranda macros, or mm. These macro packages include
a number of shorthand macros for the longer troff commands.

104

Chapter 6 : Text Processing

1.

What is vi?

3.

How do you start vi and have it position you at a certain string


in the file?

2.
4.
5.
6.
7.
8.
9.

10.
11.
12.
13.
14.

What must you do before using vi?

What are the six operations used by vi?


How do you recover a file using vi?
What are the modes within vi?

Explain what a register is it vi?

Describe how to copy text between two buffers.


How do you move to the top line of the buffer?

Write the command to filter the entire buffer through the sort
-u command.

How do you make an address and how do you reference the


marked address?
Create a string macro to write the current file to disk and edit
the next file in the argument list.
Distinguish between text processor & text editor.
State True or False :
a)

troff is a graphical user interface.

b)

.bp in troff asks to break the page.

d)

:W in vi writes the edit buffer to the original file.

c)
e)

.ps 12 would set the left margin to 12.

zz in vi is used to exit from editor, without saving the


file.

Chapter 7
MULTITASKING
MULTITASKING
REAL - TIME PROCESSES
USING THE JOB SHELL
SWAPPING AND PAGING

106

Chapter 7 : Multitasking

MULTIPLE COMMAND, ONE SYSTEM

Multitasking is a fancy computer-speak way of saying that the


operating system can do more that one thing at a time. While this may
seem like a simple matter, its really not; personal computer users
have been screaming for a multitasking operating system for years.

UNIX documentation doesnt actually often use the term multitasking


instead, UNIX is said to be multiprocessing - the same thing described
differently. When you run a UNIX command, like ls or cat, youre
running a process. When you boot the UNIX operating system, you
are actually launching a series of processes without consciously
doing so. On a large multiuser system, there may, be literally
thousands of processes running at a given time.

These process complete with each other for computing resources.


Running programs in the background, as described earlier, is a way
for the UNIX user to allocate resources efficiently. Such allocation is
necessary to keep the system from bogging down, especially a large
multiuser system with less-than-adequate resources. If there are
more process running than can fit in your systems random-access
memory (RAM), then UNIX uses a hard disk as extended RAM in a
action called swapping to disk is not the most desirable of solutions;
many experts advise the purchase of UNIX systems with huge amount
of RAM. UNIX workstations with 64 megabytes of RAM are not
uncommon these days, especially those systems dealing with graphics.

When you boot a UNIX system, the first process launches a program
called init, which then launches other processes. Init is the mother
of all UNIX processes- or, as referred to in UNIXdom, init is a parent
to other processes, which in turn can act as parents to additional
processes, called child processes. It is, ultimately, the ancestor of all
processes running on the system.
When we describe the shell and its importance in running programs
for you, we were referring to the shell acting as the parent and
managing other child process. Unless you tell it otherwise the shell
waits while you run a child and returns with a prompt after the child
process is finished, or dies. If a child process dies but this fact is not
acknowledge by the parent, the child process becomes a zombie.
Its up to the operating system to keep track of these parents and
children, making sure that processes dont collide. This means
scheduling processes to within a fraction of a second, ensuring that
all processes have access to precious CPU time. Its also up to the
operating system, through the init program, to manage child processes
that have been abandoned by their parents. These abandoned
processes are called orphans.
Through we have mockingly referred to the high level of abstraction
associated with the UNIX operating system, using names like parent,

Chapter 7 : Multitasking

107

orphan, zombie, and child to describe the various stages of processes


is a very useful thing; it helps both users and programmers visualize
very intangible actions.

To see what processes are running on your system, use the ps


command.

$ ps
PID
89
93
95

TTY
p1
p1
p1

TIME
0:01
0:00
0:01

COMMAND
xterm
csh
ps

Because we used the command on a single-user UNIX machine, our


list of running process is not very long. If youre working on a large,
multiuser systems and ask for the all the processes running, your list
may be pages long. The third field, which covers the time the
processes have run, may be of interest if there are some inordinately
large numbers present. Most UNIX commands, even very complex
ones, dont take tons of time to complete.
If you need to view all of the processes running on the entire system
use.

$ ps -e

To get a full view of the whole of the whole system, you can use:
or

$ ps -ef

$ ps -e1

Depending on the size and number of users on your system, you may
regret using this option.

For our purposes the most important column is the first one, which
lists the IDs of running processes. When the kernel launches a new
process, it assigns an ID number to the process.

This number is important because it allows you to manipulate the


process via the ID number. For example, there are times when you
may want to kill as process because its using too many precious
system resources or not performing in the manner that you anticipated.
If the process is running or not foreground, you can press the Delete
or Break Keys to stop the running in the background or has been
launched by another user at another terminal, however, you must kill
the process via the kill command.

$ kill PID

Using the PID returned by the ps or other commands. This sends a


signal to the process, telling it to cease and desist. Most processes
dont know what to do when they receive a signal, so they commit

108

Chapter 7 : Multitasking

suicide. Not all processes respond to the straight kill command for
instance, shells ignore a kill command with no options. To kill a shell
or other particularly stubborn processes, use kill with the -9 options.

$ kill -9 PID

This sends an unconditional kill signal to the process. If you have


many processes to kill, you can wipe them all out with.

$ kill 0

This kill all of the processes in a current process group, which


oversees all processes created by a common ancestor, usually the
login shell.

System V Release 4 contains support of real-time processes, which


ensures that a given process will be executed at a given time, no
matter what other processes are running. This is a radical departure
from pervious versions of UNIX, which used various algorithms to
allocate system resources more equally. With real-time processes,
the systems does not interrupt a process for any reason until the
process is completed.
Using real-time processes is important in many fields, including
multimedia, factory automation, and medical computing.

The job shell, jsh, may not be the most frequently used shell, but it
does a credible job at allowing you tight control over multiple jobs.
This is a situation where knowledge of processes is important;
otherwise, the many nifty features of jsh would be lost on you.
For example, jsh allows you to get a decipherable list of current jobs:

$ jobs
[1]
+
[2]
-

Running
Suspended

sort AL_West
>
sort
AL- East>

AL &
AL &

Both of these commands are running in the background. However,


job number one is currently running, while job number two is
suspended.

Armed with this information, theres a lot you can do with the job
shell. For instance, you could kill the job with the ever-popular kill
command. However, theres a little difference when using it in the job
shell you must combine the job number with a percentage sign (%) as
in the following command line, which kills job number one:

$ kill %1

The job shell also allows you to stop (suspend) a job:

Chapter 7 : Multitasking

$ stop %1

109

The neat thing here is that you have the option of starting the
command again in either the foreground or in the background. To
start job number one in the foreground use the following command
line:

$ fg %1

To start job number one in the background, use the following


command line.

$ bg %1

As we mentioned above, UNIX uses hard-disk space as an extension


of RAM when theres no RAM free for processes.

The mechanism is simple. When you launch a new process, the kernel
attempts to fit the process in an unused portion of RAM. If theres
RAM available the kernel loads the process and begins execution. If
theres not enough RAM available, the kernel looks for a loaded
process thats not running at that particular moment. The process is
then moved to a special area of the hard disk devoted to swaps, and
the new process. The kernel will then swap in the previous running
process if its activated by the user if enough RAM becomes available.
Swapping to and form disk slows down a system tremendously; this
action is called thrashing in UNIXdom, and it serves as a very vivid
metaphor so that you can envision exactly whats happening to your
disk(s). As we said before, a more elegant way of supporting many
users would involve buying enough RAM to allow everyones programs
to be active in RAM simultaneously. Its a waste of a good UNIX system
to be spending most its time accessing the hard disk.

Newer UNIX systems take the notion of swapping a step further with
the implementation of paging, also known as virtual memory.
Paging is very similar conceptually to swapping but increases server
efficiencies that help minimize thrashing on many systems.
If your UNIX system support paging , all memory and programs are
divided into pages, which are equally sized . When you launch a
process, the kernel searches for a page of available RAM, and into
that is loaded the first page of your programs runs, it may need
additional pages for data or execution space, and so the kernal looks
for more free pages. If no paging area on your hard disk. Process are
not grouped contiguously, and one portion of a process may be active
while another portion may be paged out. Because these processes can
be split, this method of using hard-disk space as RAM requires
special hardware support from the CPU.

How is paging more efficient? With swapping, entire processes were


swapped to disk, including both used and unused portions of the

110

Chapter 7 : Multitasking

process. With paging, small portions of different processes are paged


at any given time. For example, most of the time youre using a word
processor, you dont run the spell checker. Under UNIX, the memory
pages used by the spell checker can be paged to disk with no ill
effects. In such a case, you probably wont know the difference.

Chapter 7 : Multitasking

111

UNIX systems run multiple tasks at once, under the official


rubric of multiprocessing. Because of multiprocessing, UNIX
supports multiple users and multiple tasks. These tasks, or
processes, are stared by the process called init. The init
process start the system and gets is going. This init process,
process 1, then becomes the parent for a whole set of processes.
These child processes, in turn, launch other processes. Finally,
your login shell is launched and becomes the parent for all the
processes that you, as a UNIX user, create. To get a snapshot
of all the separate UNIX uses, try the ps command:

$ ps

The kill command, contrary to its name, send a message,


called a signal, to a process. Since most processes dont know
what to do about a signal, the processes commit suicide.
Thus, in a backward sort of way, kill kills processes. To kill
a process, use:

$ kill PID

Where PID is the processs IF number, which you can get from
the ps command.

Because UNIX can run more processes than it has RAM for,
UNIX systems usually
support swapping or paging, both
move a process or portions of a process to disk, freeing
memory for other processes. If your system is constantly
paging or swapping, youll soon see what thrashing means as
your system slows to a crawl. To avoid this, you need to run
less processes or buy more RAM.

Chapter 8
ADVANCE NETWORKING
TECHNIQUES
ADVANCE NETWORKING TECHNIQUES
FREE SOFTWARE & FTP
SURFING THE NET
READING & WRITING THE NEWS
THE WORLD WIDE WEB

114

Chapter 8 : Advance Networking Techniques

REACH OUT & TOUCH SOMEONE

The ability to link different computer systems has always been an


important part of the UNIX operating system UNIX systems have the
ability to call other UNIX systems directly, and thousands of UNIX (as
well as non-UNIX systems) have been linked together in loosely
administered network distributing files, news, and mail worldwide. In
addition, most companies with UNIX workstations tightly connect
their computers with high- speed network links, using popular
networking protocols such as Ethernet or Token Ring.

INFORMAL COMMUNICATION
uucp Command

UNIX can use several different methods of transmitting information


between systems. Originally, UNIX-to-UNIX Copy Program (UUCP) was
written to communicate between systems via ordinary telephone
lines. The uucp program allows you to copy files from one system to
another. Today, these connections can take place between those
same telephone lines via modern ( at all speeds, from 2400 bits per
second to 19.2 kilobytes per seconds) direct wiring, a local-area
network, or a wide-area network connected via dedicated phone lines.
Although the connection mechanisms have changed. The basic UUCP
system has not and remains mechanism-independent, which makes
your life much simpler. As a user, you dont need to know the
specifications of the connection mechanism; all you need to know is
how to access the utilities that make communications possible.

In a rather confusing situation UUCP refers both to a specific


command (UUCP) and a series of related commands ( most of which
begin with uu). In this chapter uucp will refer to the specific uucp
command, while UUCP will refer to the general command set.

A UUCP Primer

At their core the UUCP command allows machines to communicate


directly via network links or telephone connections. They are limited
in scope and are geared for the rudimentary purposes of sending
along files, electronic mail, and ( Sometimes) Usenet news.
In this chapter we wont cover all of the UUCP command , instead ,
well focus on the few youre likely to use. Well also avoid configuration
issues, which are best left to a system administrator.

Before you use uucp, youll need to know which machines are
connected to yours. The uuname command does just this :

$ uuname
geisha

Chapter 8 : Advance Networking Techniques

spike
khan
kirk
picard

115

Why is this information important? Because youll need to specify


machine names with the uucp command.

Using UUCP

Basically, the uucp command is used to copy files from one machine
to another. At first glance, in this age of Internet and the information
superhighway, you may think that this is incredibly retro technology.
And, conceptually, it is.
Realistically, however, the uucp command has its widest application
in the corporate world, where interconnected computers are very
common. In these situations the corporate systems may not be tied
to the outside world, but only connected to other corporate systems.
In this case the uucp command is a handy way of transferring a file
from your system to the corporate headquarters in Chandigarh.

The best way to understand the uucp command isnt to think of it as


this strange and unfamiliar networking command - just think of it as
an extended version of the common cp command, which you used
earlier in this book, instead of downloading and uploading files from
a local directory, youre using uucp to download and upload files from
another machine.

Theres also one added advantage to the uucp command. All in all, its
a rather secure method of transferring files, when everything is set up
correctly. The uucp command, as well as the UUCP utilities, can
enact very specific guidelines on where files can be uploaded to or
downloaded from .
Lets look at a typical uucp command line.

$ uucp chap9.txt spike/usr/spool /uucppublic/chap9.txt

While this may seem to be an usually long command line, a closer look
will show that its a rather simple one.

Depending on your version of UNIX, you may have a set of utilities


that allows you to link directly to another computer using the network
Transmission control protocol/Internet Protocol (tcp/ip) protocols.
Both BSD and UNIX System V Release 4 feature these protocols and
some vendors have implemented these protocols while still supporting
older versions of UNIX.

The handiest use of TCP/IP is the ftp command, which allows you to
grab files from remote machines, your computer is networked with.

116

Chapter 8 : Advance Networking Techniques

Because of UNIXs history in the public sphere, theres a log of free


software available for the taking. Emacs, for instance, is available
from any number of machines that support downloads. Or you could
acquire the entire free software Foundation (FSF) software collection,
GNU, which includes GNU Emacs (Richard stallman heads the FSF
and wrote the original version of emacs), GCC (A widely used C
computer), GNU chess ( which has been ported to many different
machines, Weve even seen it compiled for use with PCs running
Microsoft windows) and much more-in source-code form. Similarly,
you could acquire the entire X-window system via anonymous ftp,
though this is a major transfer of data.

USING FTP

The ftp command can be used to connect to any other computer on


your network running ftp. If your system is connected to the internet,
you can use ftp to access files from other internet computers worldwide.
These machines you net work with may or may not be running the
UNIX operating system; this operating system independence is what
makes ftp so widely used.
Ftp is interactive software, which means it asks you for information
at specific times. Start it with the following:

$ ftp
ftp >

Youll be presented with the ftp prompt, where you enter special ftp
commands. To get a list of available commands, type a question mark
(?) or help at the prompt:

ftp > ?
or
ftp > help

The most common ftp commands are listed in following table:


Command

Result

ascii

Uses ASCII as the file-transfer type.

binary

uses binary as the file -transfer


type.

bell

Rings the bell when file transfer is


complete

bye or quit

Terminates ftp session.

Close

Ends ftp connection to remote


com puter, but kee ps loc a l ft p
program running.

cd

delete filename

Changes directory on the remote


machine.

Deletes filename
computer

on

remote

Chapter 8 : Advance Networking Techniques


get filename

get filename1 filename2


help

mput filename
Pwd

117

Gets filename from the remote


machine.

Gets filename1 from the remote


machine and saves it locally as
filename2.
Lists available commands.

Copies the local filename to the


remote machine.

Lists the current directory on the


remote machine.

WHAT DO I DO WITH THE FILE ?

If you download an ASCII file, you can view it using any editor,
including vi or emacs.
If youve downloaded a compressed binary
file, you will have to uncompress it (and perhaps unarchive it) at the
command line using uncompress, unpack, tar, or gzip. How do you
know which one to use.

If the file ends in Z, use the uncompress command

If the file ends in Z, use the unpack command:

If the file ends in gz or tgz, use the gunzip command:

If the file still has a suffix of tar after using these commands,
use the tar command to unarchive it:

$ uncompress filename.Z
$ unpack filename.z

$ gunzip filename.gz

$ tar xvf filename.tar.

Although most UNIX systems do feature some level of connectivity to


the outside world (leading to the ubiquity of electronic mail), full
access to the Internet- as defined by the ability to access the world
wide web- is available to only a minority of UNIX users. This is
changing rapidly, as UNIX system administrators find that full access
to the Internet can be helpful for them, as well as for employees.
As always to see what level of internet access your UNIX system has,
check with your system administrator.

The Usenet and Newsgroups

The Internets roots can be traced to the Usenet, a worldwide messaging


system. The usenet, while technically comprising a portion of the
Internet, is known best for electronic-mail and newsgroup distribution.

UNIX insiders brag of being on the net, but what actually constitutes
the net - Internet or Usenet - depends on the user and their system.
Though the two are linked, there are crucial differences, and more

118

Chapter 8 : Advance Networking Techniques

likely than not the braggart is on the usenet, since anyone (essentially)
can get on the Usenet.
Thousands of computers are linked - worldwide - in a loose network
called the Usenet. The Usenet is a public network of linked UNIX and
non-UNIX machines, dedicated to sending information to companies,
schools, universities, the government, research laboratories, and
individuals.

The Usenet performs a variety of services, but perhaps the most


popular service involves newsgroups. A newsgroup is a discussion of
various topics, ranging from computing to sociology to boomerangs to
Barney the Dinosaur. In fact, there are thousands of Usenet
newsgroups. Some are trivial and a waste of bandwidth, while others
are of interest to only a small set of users.
These newsgroups are divided into classes, to better allow users to
figure out what to read in the plethora of information arriving daily.
Table 10.1 covers the major newsgroup classifications.
Name
alt

biz

comp
misc

news
rec
sci

soc

talk

Subject

alternative hierarchy, not subject to other


rules
business- related groups
computing

miscellaneous subjects
news about the Usenet
recreational activities
science

social issues
talk

Not only is this Computer-dweeb heaven, but the Usenet provides


valuable information on everything from vegetarian recipes to buying
a house to technical difficulties programming Macintosh computers.
There are Usenet newsgroups for just about every topic you can
imagine. In addition, there are also regional newsgroups.

While the Usenet can be a powerful information source, youll also


find a lot of misinformed, inaccurate, biased, and generally dumb
opinions, and nearly any one can get on the Usenet, so take what you
read with a grain of salt. Generally, the more technical the group, the
better the information youll get. The group comp.compilers (
information on writing compilers for computer languages) certainly
contains more unbiased information than comp.sys.next.advocacy
(advocates- an unbiased group if there ever was one- of Next
workstations)
However, there are many Usenet newsgroups that youll find useful.
Being technical types ourselves, we regularly pursue the newsgruops

Chapter 8 : Advance Networking Techniques

119

relating to UNIX the X-window System, and related topics (electronicmail packages like elm and pine, software like emacs)

These classifications are broken down into specific newsgroups. The


syntax of a newsgroup name is simple the name of the classification
followed by a descriptive suffix. For instance, the name of the
newsgroups devoted to questions concerning the UNIX operating
system is comp.unix.questions. Note the use of periods to separate
the elements. A listing of some popular newsgroups is listed in table
below:
Newsgroup

Topic

Comp.databases

Database- management issues

Comp-Source-Unix

UNIX source code

Comp.Unix.questions

Questions about the UNIX operating


system

Comp.lang.C
Comp, text

Misc.jobs.offered
rec.music-gaffa

sci.space.shuttle

C-language issues

Text.processing issues
Job openings

The music of Kate Bush

Issues associated with the NASA


space shuttles

Although all the news items are text files and in theory could be read
with vi or emacs, there are so many of them in so many separate files
that its not really feasible to read each file. A full Usenet newsfeed,
that is, all of the incoming message files from all the worldwide
newsgroups, adds more than 40 megabytes of files to your disk each
day. Thats how a type of software, called newsreaders, evolved.
These newsreaders help you sort out, with varying degrees of
usefulness, what to read from the hundreds of new files that appear
daily. The basic idea is to read those messages youre interested in
and skip the rest. Theres simply no way to read every incoming
message, even if you spent all day in front of your computer.

We are not going to cover any of the many news readers in depth: each
system, it seems, features its own news reader. We find that the most
popular programs are:

readnews, an older, line-oriented program with limited power.

rn, a reader with expanded search capabilities.

vnews, a vi-like reader that displays newsgroups one item at


a time.
xrn, an X window graphical version of rn.

tin, a threaded reader that arranges messages by topic.

120

Chapter 8 : Advance Networking Techniques

GOPHERS - INFORMATION ORGANIZERS

Another method of organizing the offerings of the Internet is through


gopher server. Named after the mascot at the University of Minnesota
where it was developed, gopher organizes files by menus. You can use
gopher to retrieve files from an ftp site, for instance: the filename
maybe listed in a gopher menu, but to you its all one big organized
file system.

The beauty of gopher is that it works both in a text-based environment


and in a graphical environment. In a text based environment, the
menus within a gopher server can be selected by using the scroll keys
or typing in the number of the menu. Within the graphical (i.e.Xwindow) environment the menu selections can be double-clicked with
a mouse.
Every version of gopher works basically the same way as you begin
it by entering gopher on the command line;

$ gopher

or
$ xgopher

If your system is configured properly, youll be connected to a home


gopher server on the internet.

Much of the buzz surrounding the Internet can be traced to the World
Wide Web and the tools for accessing it - Mosaic, Netscape, and their
ilk.
And, quite honestly, the hype is justified. At its best, the World Wide
Web is an incredibly, efficient and exciting way of distributing
information. The potential of the web has been barely scratched, and
when all is said and done the web will profoundly alter publishing as
we know it.

PAGE LIMITS

Such grandiose statements, of course, are a dime a dozen in the


computer world. But the World Wide Web is a case where the hype is
warranted - both because of the makeup of the web itself and the
economics of using the web.

It s best to look at the World Wide Web not as a computer service, but
rather as a publishing medium.
At its core, the World Wide Web is actually an ingeniously simple
beast. A web browser, such as Mosaic or Netscape, sends a request
over the network to a web server; the request can be one of five
formats. The Server then honours the request by sending a text file
formatted in the Hyper Text Markup Language (HTML), which inserts

Chapter 8 : Advance Networking Techniques

121

tags in the text. The text file is then rendered by the local web
browser, which matches the tags to resources on the local machinefor instance, a tag for TITLE would be rendered in a font and point size
set up through the web browser.

The HTML language also allows graphics and hypertext links to be


embedded in the document. Most graphics files are in the GIF and
XBM file formats. The hyperlinks are noted with their own tag and are
usually set off in a different color within the rendered document. For
instance, under a heading titled Other Resources, there maybe a line
colored blue that says Sun Micro-systems Home Page. To the web
browser, however, theres an embedded web address (in this case,
www.sun.com). Double-clicking on Sun Micro-systems Home Page,
initiates a request to the web server www.sun.com. You dont need to
know the www.sun.com.address, you only need to know how to use
a mouse.

ACCESSING THE WEB

To access the World Wide Web, youll need a web browser. The most
famous web browser is Mosaic, originally from the National Center
for Supercomputer Applications (NCSA) at the University of Illinois.
That isnt to say that mosaic isnt the best web browser on the market,
There are a host of competitors in the UNIX/X-window world, including:

GWHIS (a commercial Mosaic implementation from Quardralay)

Lynx (a freeware web browser written in TCl /Tk)

Enhanced Mosaic (a commercial version of mosaic from a


variety of resellers)
Viola (a freeware browser)
Netscape Navigator.

122

Chapter 8 : Advance Networking Techniques


The UNIX operating system features a series of commands
that allow you to concept directly to other UNIX systems. The
most popular commands are related to UUCP, the UNIX-toUNIX Copy Program. The most common of the UUCP commands
is uucp.
The ftp command allows you to transfer files between network
systems. The UNIX operating system contains the tools
necessary to link other computer systems in a way thats
completely transparent to the end user.

The discussion of UNIX networking and communications ends


with this discussion of the Usenet, the Internet, and the World
Wide Web(WWW). Each of the three tools can be useful in its
own way: The Usenet for reading newsgroups, the Internet for
grabbing files and useful information, and the World Wide
Web for staying connected in this of interconnectivity.
To use the resources listed in this chapter, youll need to
expand your list of UNIX tools past a news-reader to include
programs like archie, gopher, and a web browser like netscape,
which generally are not included in most commercial UNIX
distribution.

Chapter 9
ADVANCE UNIX
COMMANDS
Awk command
Perl command
A First Perl Script
Sed command
At command
Batch Command
Cron Command
Bc Command
BACKING UP YOUR SYSTEM

124

Chapter 9 : Advance Unix Commands

As weve repeated throughout this book, perhaps the greatest strength


of the UNIX, operating system is that its collections of small, useful
tools that can be combined to form even more powerful tools. Here,
few more tools have been taken, which are considered advanced tools.
Here, the tools have been discussed in brief, altering you to their
existence.

awk Command

Developed by three Bell Labs research ers (Alfred Aho, Peter


Weinberger, and Brian Kerighan- Hence named awk), awk is
technically a programming language , but used much in the same
manner as other UNIX tools. Hence its inclusion in this chapter.

Awks primary value is in the manipulation of structured text files,


where information is stored in columnar form and information is
separated by consistent characters. Awk takes these structured files
and manipulates them through editing, sorting, and searching.
Consider the following file use_addre:

Rashmi

Ambica
Smedia
Sanjeev

286

280
279
284

555-6674

555-4221
555-1112
555-2121

ra

amb
10
smedia 2
spike 12

Lets sink into the trap of abstraction for a minute and compare our
example file output to a two-dimensional graph. Each row across is
called a record, which in turn is made up of vertical fields or columns,
almost like a database. Awk allows us to manipulate the data in the
file by either row of column, which makes it more powerful and useful
than the tools discussed earlier.
Using the Awk command is not a complicated process. The structure
of the awk command looks like this.

$ awk [option] pattern action

The only options available with awk are -F, which allows you to
specify a field separator other than the default of white space, and f, which allows you to specify a filename full of awk commands
instead of placing a complex pattern and action on the UNIX command
line.

Here we should define our terms. A pattern can be an ASCII string ,


a numeral, a combination of numerals, or a wildcard, while action
refers to an instruction we provide, So, essentially, awk work by
having us tell it to search for a particular pattern; when it has found
that pattern, then awk is to do something with it, such as printing the
pattern to another file.

Chapter 9 : Advance Unix Commands

The simplest awk program merely print out all lines in the file,

$ awk print use_addre


Rashmi
286
555-6674
Ambica
Smedia
Sanjeev

280
279
284

555-4221
555-1112
555-2121

ra

125

amb
10
smedia 2
spike 12

Continue our previous example, lets say we wanted to pull all records
that began with the string Ambica. Wed use the following :

$ awk $l ~ /Ambica/print $0 use_addre

Heres what the command means, part by part:

$1: Tell awk to use the first column for the basis of further
action. Awk will perform some section on a file based on either
records or fields; a number beginning with a awk to work on
a specific field. In this case $1 refers to the first field.
~ : Tell awk to match the following string.

/Ambica/: The string to search for.

print $0:
Tell awk to print out the entire record
containing the marched string. A specially use of the
$ sign is with the character 0, which tells awk to use
all of the fields possible.

use_addre: The file to use.

In our case, awk would print the following to the screen:

Ambica 280

555-4221

amb

10

Not every action needs to be the result of matching a specific pattern,


of course. In awk, the tide(-) acts as a relational operator, which sets
forth a conditional for awk to use. There are a number of other
relational operators available to awk users that allow awk to compare
two patterns. Awk support the same relational operators as found in
the C programming language. They are listed in table below:
Operator Meaning
<

Less than

Usage

<=

Less than equal to

$1 <= Rashmi

!=

Not equals

>=

Greater than

$1 != Smedia returns every field


not containing Smedia.

>

Greater than

==

Equals

equal to

$1 < Rashmi returns every pattern


with an ASCII value less th an
Rashmi.
$ 1 = = S m e di a r et u rn s e v er y
instance of Smedia.

$1 >= Sanjeev.
$1 > Sanjeev

126

Chapter 9 : Advance Unix Commands

We could increase the sophistication of awk searches in a number of


ways. Firstly we could incorporate the use of compound searches,
which uses three logical operators:
&&

which works the same as the logical AND

which returns anything NOT equaling the original.

||

which works the same as the logical OR

For example, lets say we wanted to know how many had a value in the
fifth field that is greater than or equal to 10:

$ awk $5 > 10 print $0 use_addre


Ambica
280
555-4221
Sanjeev
284
555-2121

amb
spike

10
12

We can also combine tests, to print out, for example, all workers who
have the fifth field less than 10 and the second field greater than 280:

$ awk $5 < 10 && $2 >280 print $0 use_addre


Rashmi
286
555-6674
ra
8

While these examples are obviously contrived, you can use awk to
help pull out all entries that share certain postal (ZIP) codes, or all
employees who have a salary in a certain range. Were just scratching
the surface with awk.
Awk can also be used to return entire sections of data, as long as you
can specify patterns that begin and end the section. To return the
records of Rashmi and Smedia and all between use the following:

$ awk $l ~ /Rashmi/./Ambica/print $0 use_addre


Rashmi
286
555-6674
ra
8
Ambica
280
555-4221
amb
10
Smedia

279

555-1112

smedia 2

If we dont want to print the whole record, we can print just a few of
the fields, as in the example below, which prints out field2 and 1:

$ awk $l ~ /Rashmi/./Ambica/print $2.$1 use_addre


286
Rashmi
280
Ambica
279
Smedia

As with other UNIX commands, awk can be used in pipes, and its
output can be directed to other files or directly to the printer. For
example, if we were looking through a large file and expending many
matches to a particular string , We might want to direct that output
to a file or to a printer. For example to use awk with the UNIX sort
utility, we can sort the output of the last example:

$ awk $l ~ /Rashmi/./Ambica/print $2.$1 use_addre|sort


279
Smedia

Chapter 9 : Advance Unix Commands

280
286

Ambica
Rashmi

127

(Note that this is sorting on the leading number).

perl Command

Perl is a freeware scripting language developed to handle a number


of system administration tasks. Perl stands for Practical Extraction
and Report Language. The whole point of the language is to make it
easier for you to extract data form UNIX and output reports on things
such as Usenet news, disk usage, and a list of all users on your
systems, sorted in order of largest disk usage.

When approaching perl, the first question to ask is : Do you have perl
on your systems? Many UNIX systems, such as Linux, come with perl
built in. To check this out, simply type in :

$ perl -v
perl: command not found.

See the section on acquiring perl, below, for more on getting perl if
you dont already have it.

A FIRST PERL SCRIPT

Perl like most UNIX scripting language, uses the # as a comment


marker. Any line with # is ignored from the # onward. Like the echo
command in shell scripts, perl offers the more versatile print
statement, as we show in the following example:

#! /user/bin/perl
# My first perl script.
print This is my first perl script. \n:
print oh, joy!\n:

When you run this script, youll see the following output, as youd
expert:

This is my first perl script.


oh. joy!

The \n stands for a newline, or infeed character, and is typical UNIX


parlance. You can also prompt for data in perl, using the following
odd syntax:

#! /user/bin/per1
# Prompting for input in perl.

print What is your first name: :


# <STDIN> stands for standard input: the keyboard.
$ first_name = <STDIN> :

128

Chapter 9 : Advance Unix Commands

# Remove trailing linefeed.


chop ($ first_name);
printf What is your last name : :
$ last_name = <STDIN>;

chop($last_name);
print Your name is $first_name $last_name. \n;

When you run this script, youll see the following prompts:

What is your first name: Rashmi


What is your last name : Syal
Your name is Rashmi Syal.

From the above example, youll note that perl seems more difficult
than the Bourne shell for getting input from users.

sed Command

The sed command can be likened to the text editors vi, emacs, and ed.
However, the vi, emacs & ed. Sed can be thought of as a filtering text
editor; procedurally, you use the sed command with the following
steps:

Read in text from file

Display new text on screen or save to file.

Make changes in the text

These procedures are specified all in one command line. A typical sed
command line should look something like this:

$ sed -n -e operation -f scriptfilename filename

where -n refers to a specific line or lines, operation refers to one of the


many available sed operations, scriptfilename refers to a file that
contains a longer list of sed operations, and filename refers to the file
that sed works on.
The various command-line options are explained in greater detail in
following table :
Command

Result

-f

Specifies a script file. If you plan on using


many operations regularly, than its best
to save them in a script file for future use.

-e

-n

Explicitly tells sed that what follows is an


operation. If you only use one operation,
than you can omit the -e.

Specifies a specific line number or a range


of line numbers to use.

Chapter 9 : Advance Unix Commands

Consider the following file named test:

129

Practically all major cities in India are set with an


inadequate supply of serviced land. Speculative holdings
of urban land further limit the supply. The urban land
market caters to the needs of upper and middle income
groups while the land owners reap most of the benefits of
rising land values in the process of urban development,
the low income majority are the most affected in this
process.

Lets begin by using sed display only a portion of the file test, like the
second and third lines. Do so with:

$ sed -n 2,3p test

On your display, youd see the following:

inadequate supply of serviced land. Speculative holdings


of urban land further limit the supply. The urban land

If we wanted to write the result of our command to a file, we could do


so as follows:

$ sed -n 2.3p w filename test

where filename is the name of a file.

Some filename is the name of our little examples:

Because we used only one operation, we omitted the -e option.

We specified certain lines for sed to work on. If no lines are


specified, sed assumes that is to work on the entire file.

We listed the command within single quotes, which tells sed


that everything contained in the quotes is part of the same
operation.

Printing of course, is not the only operation available to sed users.


Given below are other major operations:
Operation

Result

c\string

Chan ges specified lin es to th e


specified string

a\string
d
i
l

Adds the string

Deletes specified lines or string

I n s er ts sp ec if ie d s tr in g b ef or e
specified lines.

Lists the file or specified portions


thereof. Useful because it displays
characters normally used for
formatting; for example, tabs are
printed with the > character.

130

p
r filename
s/string1/string2
w filename

at Command

Chapter 9 : Advance Unix Commands


Prints to standard output - unless
specified otherwise, your screen.

Inserts an entire file after a specific


line.
Substitutes string1 for string2.

Writes specified lines to filename.

You can use the at command to relieve pressure on the system by


running system-intensive commands in the middle of the night, to
send mail messages involving long-distance charges when rates are
lowest, or to backup a large hard disk at some regular interval. Thus
At command gives you freedom to run various commands at specified
time.
Using at is simple, as you first specify a time for execution, followed
by the command line. To set up a specific command, type the
following.

$ at llam

At is very flexible about defining the time when the command is to be


run; you can use a time as in our example, or you can use a more
precise number based on military time.

After you hit the Enter key youll be placed on the following line,
without a prompt. As you recall, this is the UNIX method of asking you
for additional input. This is where you provide the command that at
is to execute; end each command by hitting the Enter key. When
youre through type Ctrl-D.

batch Command

Weve already discussed the early days of UNIX usage, when


instantaneous interaction between users and the UNIX system wasnt
always possible. Out of this need arose the batch command, which
allows you to combine many commands into one command line,
which is then run in the background without any prompting on your
part.
Use batch as follows:

$ batch

End the command by hitting the Enter key. As with at youll be placed
on a new line, as batch waits for additional input. Go ahead and type
in the commands, ending each by hitting the Enter key. When youre
finishing entering commands, type Ctrl-D.

Youll then be presented with a command prompt, so go ahead with


your other work as your batch command are quietly executed by the
system. If your command require some sort of confirmation message
or output delivered to you, the message will be conveyed as a mail

Chapter 9 : Advance Unix Commands

131

message; you wont find message propping up on your screen while


youre in the middle of some other action.
Elsewhere in this book, we have discussed running programs in the
background using the ampersand.

Command issued to batch are accorded even less priority


than command run in the background.

With batch, command will continue to execute even if you log


off the system. Background tasks are killed if you log off the
system.

Background will interrupt you should your background


command specify some kind of output or confirmation. Batch
does not; as we noted, confirmation or output is sent as a mail
message.

cron Command

System administrator have all the fun- or used to, anyway, as


evidenced by the cron command. Cron started life as a tool for system
administration, allowing the system administrator to schedule regular
tasks unattended. These tasks were stored in a file called crontab,
usually found in the /user/lib directory. Some versions of UNIX,
either pre-System V or Berkely, still allow cron privileges only to the
system administrator. However, if youre using a newer version of
UNIX youll have access to cron.

bc Command

Even through the proliferation of ubiquitous and inexpensive


calculators have made this command somewhat obsolete, the bc
command can still be used as a calculator. Use it as follows:

$ bc
l + l
2
quit

This simple equation shows how to use bc: Type it as a command line,
hit Enter, enter your equation, hit Enter, read the calculation and
type quit when youre through. Obviously, other more advanced
features are available, such as square roots, converting numbers
from one base to another, determining prime factors, control
statements for writing programs, and more.

tar Command

We advice that you back up your work often - as possible. There isnt
a computer user anywhere who hasnt accidentally erased an important
file at one time or another. In many ways, the regular and systematic

132

Chapter 9 : Advance Unix Commands

backup of files is the most important task a system administrator


fulfills - a task that you should perform regularly if you back a system
administrator. (It must be noted that tar is a command available to
Superuser. Other important superuser command are init, date &
shutdown)

What kind of files should you back up regularly? Essentially, your


system contains three types of files. System files, configured system
files and data files. System files rarely change and can be reinstalled
from the original floppies or tape, so you dont need to back up these
files often. System files that youve configured and data files, on the
other hand. Are key to the success of your enterprise. Data files form
the core of your daily computer work. If you lose 20 files that took all
day to create, you have essentially wasted the labor of a full day: And
who wants to do that?
Luckily, UNIX - the newer version, at least - features a powerful, yet
easy-to-use command for archiving and storage tar.
Tar stands for tape archiver, and it started life as a tool for backing
up files to a tape drive - Still the predominant back-up storage device
on UNIX systems.

Lets say you wanted to back up all the files in an important directory
- /usr/erc/data/reports - to make sure that you dont lose any of
your work to date. Before using tar, make sure that your current
directory is /usr/erc/data/reports:

# cd /user/erc/data/reports

Then back up the files in the directory, using the following.

# tar -cvf archive.fil

In this command we have run tar with the following;

which creates the archive;

which specific the file name of the archive;

v
.

which tells tar to be verbose- that is, report to us periodically


about its progress.
Which designates that all of the contents of the current
directory should be copied.

If, for example, we wanted to back up only those file ending with c; we
could invoke a wildcard:

# tar -cvf archive.fil *c

The above command stores all of the files ending with c into the tar
archive file named archive.fil. In this case archive.fil is just a
standard UNIX file. Since UNIX treats hardware devices as files, we
can back up our files to a tape, by replacing the file name archive.fil
with the name for the tape device, usually /dev/tape.
To restore files from the archive, use tar as in the following :

Chapter 9 : Advance Unix Commands

# tar -xvf archive.fil

133

The previous command extracts (the -x option) the files stored in the
tar archive file and places these extracted files into your current
directory. The -f option is followed by the name of the tar archive file.
And the -v option again sets tar into verbose mode, providing
important status information. The following table lists more tar
command :
Command

Result

Overwrites file permission associated with


the files in the archive.

c
t

u
w
x

Creates an new archive.

Provides a listing of the contents of archive.

Updates files in the archive. If the files


dont need updating, no action is taken.
Asks for confirmation before backing up
an individual file.
Extracts files from the backup device.

Tar is not the only backup tool available in UNIX, though we find it
the most widely used. Another backup tool is cpio, which has been
called the most difficult to use UNIX command by users.

134

Chapter 9 : Advance Unix Commands


The awk language helps process UNIX text files, especially
formatted or structured text files, such as a list of employees.
You can write awk programs or just issue awk command at
the command-line prompt.
The streams editor, sed, acts as a batch text editor. Sed
becomes really useful when you want to automate changes to
text files.

The at , batch and cron commands allow you to run commands


in the background. At runs a command at a specified time.
Cron allows you to set up commands to run at certain times
of the day or days of the week. For example, you might want
to run a daily production report at the end of the business day
You might also want to configure your system via cron to dial
out to other computer systems in the wee hours of the
morning, when long-distance telephone rates are their lowest.
To confifure cron, you create a crontab file and then issue the
crontab command.
Finally, the bc command provides an interactive calculator,
so you can balance your chekbook and solve complex
equations.

Chapter 10
THE X-WINDOW
GOING GRAPHICAL - THE X WINDOW SYSTEM
WINDOW FOCUS

136

Chapter 10 : The X-Window

The X Window system - even the concept - confuses most new users.
Is it a UNIX shell? No. Is it the all-singing, all-dancing graphical
system that will cure all your computing woes? Not yet. Is it a
standard? Yes, although some vendors - most notably workstation
giant Sun Microsystems - have been brought into the X fold kicking
and screaming. Is it a workable business-oriented environment? Yes,
but just barely.

X is complex, confusing, and bloated, but its also a graphical


windowing system X provides multiple windows (run by multiple
applications) on a graphics monitor - the bare bones building blocks
of a graphical user interface (or GUI, to use a popular and trendy
term).
X, as a graphical user interface, provides two immediate benefits for
you, the UNIX user:

First X allows you to use more of your display, because you


can access every dot on the monitor, instead of just 24 lines
by 80 characters in text mode. Graphics monitors have
dramatically dropped in price over the last few years, so that
most users can take advantage of Xs capabilities.
Second a graphical user interface eases your transition to
UNIX and speed up your daily work. Several studies clearly
indicate that a well designed graphical interface reduces
corporate training time and increases worker productivity.

Just about every modern UNIX software package, form the xmahjongg
game to the WYSIWYG (what-you-see-is-what-you-get), Asterisk word
processor, runs under a graphical interface. Unlike the cryptic dot
command introduced for troff, Asterix provides a friendly menudriven graphical interface, as does Island Write, FrameMaker, and
almost every other X-base package. All of these programs run on top
of the X Window System.

X, then, provides the basics for graphical windowing in a way that is


portable to most UNIX platforms. What makes X special is that this
graphical interface runs on just about every UNIX platform, as well as
on VMS, DOS, Windows, AmigaDOS, and the Macintosh. X is not the
only modern attempt at providing a graphical user interface - Microsoft
interfaces. So why use X? For the following reasons:

Flexibility

X allows you to layer any number of graphical user interfaces on top


of the underlying windows system. You can run Motif and Open Look
programs, or programs sporting any other interface you desire. Few
other windowing systems offer this flexibility.

Chapter 10 : The X-Window

Protability

137

X program run on a wide variety of computer systems. If your


company or university owns UNIX workstations from a number of
vendors - a very common occurrence- them the knowledge you gain
learning X will aid you on any of these platforms.

Network transparency

X program can be used across a network. The X windows system


divides computing into parts, based on a client-server relationship.
This relationship can be rather confusing but it offers the ability to
efficiently distribute applications over a network. (Well cover this in
more depth later)

Because its there

If youre using UNIX (which we assume you are, or you wouldnt have
read this far) and run a graphical windowing system. Well youre
running X. Very few non-X graphical UNIX system survive today.
Thus if you want to learn how to get the, most out of your system, then
it is good for you to learn X.

THE X SERVER

In the mini and micro worlds, a server is usually a hardware device


( a VAX, an AS/400, a Novell file server) running at the center of a
network, distributing data and processing power to networked
workstations and terminals, Because other systems on your network
have access to your display, the X server cannot be thought of in the
same way as a file server on local-area network. With X, the role of the
server (sometimes called a display server) is reversed. The server is a
program that runs on your local machine and controls and draw all
output to the display. Your local machine , whether its a PC running
SCO Open Desktop or a Sun SPARC station running Open Windows,
is called a display. The server draws the images on your physical
monitor, tracks input via keyboard and pointing device (usually a
mouse), and updates windows appropriately.
The server also acts a traffic cop between clients running on local or
remote systems and the system. Clients are application programs
that perform specific tasks. (In X the terms clients and applications
are used interchangeably.) Because X is a network environment, the
client and the server dont necessarily compute on the same machine
(although they can and do in a number of situations). Thats how X
features distributed processing. For example, a personal computer
running SCO UNIX can call upon the processing power of a morepowerful Solbourne host within a network, displaying the results of
the Solbournes computational on the PCs monitor. In this case the
client is actually running on the remote Solbourne, not your local
machine -thus distributing the processing across the network. The
idea is simple : the actual computing should take place on the

138

Chapter 10 : The X-Window

machine with the most computing power on a network, not necessarily


at the computer that a user happens to be using.

Most X user run a window manager to help control their display. A


window manager is a program that defines how the interface (that is,
the actual look of the programs) actually appears and acts on the
screen. X does not provide a specific look and feel of these windows;
that is the specific arrangement of elements on a screen (scroll bars,
title bars, etc.). As we noted before , X provides the building blocks for
a graphical interface. The user is free to layer any look and fell on top
of X.
Since the X-Windows System doesnt mandate a user interface, you
are free to layer a particular look and feel on top of it. And indeed,
most X users dont deal directly with X, but rather with vendorsupplied solutions - and thats where Motif and Open Look come in.

USING X

While you dont need to be an X expert in order to use X, its a good


idea to be familiar with the basic X-Window System.
The first step in empowerment is actually getting your hand on X. If
youre a workstation user, you probably are already using X or have
it available for use. Workstation from Sun, DEC, Hewlett-Packard,
Silicon Graphics, and IBM all feature X as a central part of their
operating environments.

If youre already working in a networked network station environment,


or work with a VAX/VMS system running DECwindows, you may be
familiar with X, A way to bring the power of X to additional users,
without the expense of additional workstations, is through X terminals.
An X terminal is more than a dumb terminal, yet less than a full
workstation. X terminals have enough horsepower to run a local
server, but yet relies on a machine elsewhere on the network for most
of its computing power.

WHAT X LOOKS LIKE

As stated repeatedly, X is a graphical user interface. It uses various


graphical elements to represent different portions of computing.
The exact graphical elements will depend on what kind of X
implementation youre using, of course: X on a PC running Unix Ware
will look different than X on a Hewlett-Packard workstation.

X uses the metaphor of windows, to represents most screen element


(no surprise there, eh?). Windows in other words, represent a
program. Normally, the windows have a title at the top of the window
that describes the program.
Of course theres more to X Window than merely windows. X also
makes extensive use of icons to represent screen elements. In most

Chapter 10 : The X-Window

139

cases an icon represents a window that has been shrunk in order to


clear up clutter on the screen. In other cases an icon can represents
an application.

Starting X

Before you can run any X application, through , you need to start the
X server. The X server takes control of a display; the keyboard, a
pointing device (usually a mouse), and at least one video monitor sometimes more in multiheaded systems.
An X server alone isnt worth much - all you get is a crosshatch
pattern and an X cursor. Youll also want to start a number of X
applications, including a window manager, when you start up the X
server. The applications are important; the X server merely provides
the infrastructure.

Unfortunately, there are number of ways to start the X server, Many


UNIX workstation vendors, in a futile attempt to add value and
distract you, customize the way you start X. While these features may
be considered value-added if you only buy workstations from one
vendor, they soon become value-subtracted as you try to learn every
systems weird customized commands. The whole point of UNIX is
thatit runs relatively the same on all platforms. Thats also supposed
to be the whole point of X. Anyway, if your system already has a
method to start X, then by all means use that method. Otherwise, you
can start the X-server with the sinit or the startx commands.

If you already running X, that is, if you see a graphics display


in front of you. you dont need to run xinit, as this (of the
equivalent on your system) has already been done for you.
Normally , xinit can run without any arguments:

$ xinit

Xinit starts the X server, a program named, appropriately enough, X,


thats normally stored in /user/bin/Xll. After starting the X server,
xinit executes the programs listed in the file .xinitrc, which is
located in your home directory, much like the .profile or .login files
used by sh and csh. This .xinitrc file lists the programs you want to
start when you launch X. This usually includes a graphical clock, at
least one xterm, and a window manager, such as twm, olwm, or mwm.

Because .xinitrc is a shell script, all the programs it launches, except


the last, should be run in the background, with an ampersand (&)
trailing the command.
When .xinitrc terminates, sinit kills the X server. This, in essence,
is how you stop X.

If you run every program in .xinitrc in background then .xinitrc will


quickly terminate, and so will your X server. Run the last program in
.xinitrc in the foreground like the example .xinitrc file shown here:

xterm - geom 80 Xx 40 + 100 + 200 &

140

xclock - geom 120x120+900+10 &

Chapter 10 : The X-Window

Obviously youll choose a program that you intend to keep around for
your entire X session. Like the pervious example, most users end
their .xinitrc file by running a window manager, such as twm.

There are two main reasons for this. First, you want a window
manager running during your entire X session. Second , most window
managers provide a menu choice that allows you to exit. This menu
choice is an easier (and easier to remember) way to quit X than typing
Ctrl-D in an xterm window, or using kill to terminate the X server.
Using the previous example, exiting the window manager also exits X.
Whatever program you choose, this last key place holder process
controls when X exits. When this process exits, X does too.
If xinit fails to find a .xinitrc file, it merely starts the X server and
one 25-line xterm window.

USING STARTX

Theres no great mystery to the startx command - it merely calls the


xinit command under the hood. Most PC UNIX-based X Window
implementations, such as XFree86, use startx to launch the Xserver. In every other respect, however, the process for configuring
xinit (such as configuring the .xinitrc file ) is the same for xtartx as
it is xinit.

The .xinitrc File

Lets go over our example .xinitrc file line by line. The .xterm
command starts an .xterm window:

$ xterm - geom 80x40 + 100 +200 &

xterm is a text-based DEC VT102 terminal emulator; certainly


nothing flashy. This is the most commonly used X program, in our
experience, even though X is such a ballyhooed graphical environment.
In this case we start an xterm window with a geometry of 80x40+100
+200-80 characters wide by 40 lines tall, and a location of (100,200),
which is 100 pixels across from the left-hand side of the screen, and
200 pixels down from the top. This command is run in the background.
Noted that xterm uses a width and height in characters (based on the
size of sters font). While other X programs specify the width and
height in pixels. This distinction can be confusing. The origin in x is
the upper-left corner. Values increase in the x direction moving right.
Values increase in the y direction going down.
The xclock command starts a graphical clock:

$ xclock - geom 120x120+900+10 &

Since most computer users are Type A personalities, they all want to
know what time it is - all the time. There are two main X clock .xclock

Chapter 10 : The X-Window

141

and .oclock. Oclock provides a rounded window on systems that


support them.
The following command launches a window manager, twm in the
foreground.

$ exec twm

Window manager control the layout of windows on the screen allowing


you to move windows, iconify them, and change their sizes. Window
Manager also give the window title bars a certain look - such as the
Motif or Open Look style (In this case we went with a neutral player,
the Tab window manager) We use exec to launch twm because exec
will overlay the shell process with the twm process, saving compute
cycles, and we all know X grabs far too many cycles.

COMMAND- LINE PARAMETERS

Most X programs accept a standard set of command -line parameters,


as listed in following table . In our case we already used the - geom
command - line parameter to set the window geometry in the example
from the previous sections.

Common X command-line parameter


Parameter

Meaning

-bd color

Sets window border color.

-background color
-bg color

-bordercolor color

-borderwidth border_width
-bw border_width
-display display_name
-fg color

-fn fontname

-font fontname

-foreground color

- geometry gemetryspec
- gemo geometryspec

Sets window background


colour
Sets window background
color.
Sets window border color.

Sets window border width,


in pixels.
Sets window border width,
in pixels.

Names the display (X server)


to connect to.
Sets foreground color.
Sets font.
Sets font.

Sets foreground color.

Sets window size & location

-iconic

Starts program as an icon.

-reverse

Turns on reverse video.

-name name
-rv

Sets application name for


grabbing resource value.

Turns on reverse video.

142

-tittle tittle

Chapter 10 : The X-Window


Sets window tittle.

-xnllanguagelanguage[terr][.code] S e t s
language,
and
optionally territory and
codest for current locale.
-xrm resource_command

USING THE MOUSE

Sets the given resource, just


like in a resource file.

The X window System requires a mouse; While it is possible to do


some things within X strictly from the keyboard, generally speaking
youll need the mouse to accomplish anything substantial.
The mouse allows you to directly control a pointer on the screen. This
pointer is your agent as your move between windows, icons, dialog
boxes, pull-down menu, and other screen elements.

X assumes that youre using a three-button mouse. While supporting


up to five buttons (Yes, there are mice with five or more buttons, but
they tend to be limited to the CAD/CAM field.) Internally, X refers to
the three mouse buttons as Button1, Button2, and Button3, For the
purpose of this discussion, well refer to the left, middle and right
mouse buttons, assuming that your mouse uses the standard X
configuration (which is geared for the right -handed computer user).
Left-handed people, or users not comfortable with the default mouse
configuration, can change the mouse buttons through an X-client called
Xmodmap. However, this client isnt geared for the beginning computer
user. If you want some more information on xmodmap, check in some
of the more advanced X window texts.

Using the mouse to move around the screen real estate isnt a big
deal, particularly if youve already done some work on a computer
running Microsoft Windows ,OS/2, or the Macintosh operating system
. However if youre unused to working in a graphical environment with
a mouse, there are a few things youll need to master before you
become completely at ease.
X allows you to perform many distinct acts with the mouse-probably
more than you thought possible. Roughly speaking, X mouse actions
can be divided into four groups:

Click : Press a mouse button and than release it . The act


should be fluid ; that is you shouldnt pause too long between
pressing the mouse button and then releasing it . Two clicks
in a row represents a double clicks in a row represents a
double-click.
Drag : Position the pointer over an on screen object (such as
a window or an icon), press the left mouse button, and then
move the mouse while continuing to hold down the mouse
button. As you move the mouse, the window or icon (or an
outline representing the window or icon, depending on your
system configuration) will move on the screen, When the

Chapter 10 : The X-Window

143

window or icon reaches your desired destination point, you let


go of the mouse button. The point, of course, is to be able to
move windows and icon from one part of the screen to another.
You also use the drag motion when you pulldown a menu and
make a selection from the menu.
Press: Simply put, you press down the mouse button. At times
youll want to release the mouse button immediately; at other
times youll want to keep the button passed while you drag a
window or choose from a menu.

Release: Of course, this is when you let go of the mouse


button.

As you play with the mouse and the pointer , youll notice that not
every window is always the same color on the screen, and that at
times a window wont be able to accept your input.
In X, windows are said to have focus (or sometimes input focus),
which is a fancy way of stating that you can type into or manipulate
a window. Only one fancy window at a time can have focus. Depending
on the window manager in use, X does tell you which window has the
focus; in most instances the window that has the distinctive color (or,
actually, the only color) is the window with focus.

With most window managers, you need to explicitly set the focus by
moving the pointer over a window and clicking on the left mouse
button. If you click on a window thats partially obscured by another
window, giving it the focus will move the obscured window on top of
the previously obscuring window. (This sound much more complicated
than it really is. Trust us.) Dont worry if you have a window partially
obscuring another; the obscured window is still fully functional and
running a program.

Setting Up the Proper Paths

One problem that way plague your system is not being able to find the
X programs in your command path. If you get a command not found
error when you run any X command, this is probably the case.

The default location for X window binary executable is in /user/bin/


XII, which is a directory that isnt in your normal command path unless your system administrator or workstation vendor took care of
this detail for you. Make sure your path includes the directories
where your X program reside. With Open windows, the default
location for X program is in /user/openwin.

WORKING WITH XTERM

Despite all the fuss over the X Window Systems value as a graphical
user interface for UNIX we find the most frequently used X program
to be xterm.

144

Chapter 10 : The X-Window

After all is said and done, most users still need to enter UNIX
commands at a command shell prompt, mainly because X-tools
simply arent advanced enough to completely hide the command
prompt and obsolete the shells. Luckily, were already well-versed on
the UNIX shells. xterm manager the interface to X so that all of your
old text-based program, like the vi text editor or the elm electronic
mailer, as well as UNIX command work just fine inside xterm.
It seems odd to use a graphical windowing system merely for commandline windows, but xterm provides more than a simple command line.

You can control xterms window size and location, fonts (and
font size), as well as the foreground and background colors.)
You can have multiple xterm window on screen at the same
time - and copy and paste between them. They can overlap or
sit side-by - side.

sterm provides a handy scrollbar to review previous commands


or the long output of complex programs. In fact, our standard
X Environment includes two or three very large xterm window
on the screen. This provides the base for a very productive
software development environment on UNIX.
If you like the standard 80-column by 25-line text display
then youll like an 80- column by 46-line text display much
better, particularly if you can have two of these side-by side
- a better setup than multiple 80x25 character virtual screens
offered on many 386/486 systems.

STARTING XTERM

You can start an xterm window (normally for another xterm) with the
following command

$ xterm &

This will start the xterm in the background. You must be running the
X sever the X-sever for this to work. Normally, youll start the xterm
in the background, so that you can continue to work in our current
terminal. You may want to arrange your X start-up configuration to
launch more than one xterm Window - all in the background, by
editing your .xinitrc file.

Setting X Fonts

Like most X application xterm will accept a font name command line
parameter Use either - font font name or - fn font name

$ sterm - font fontname &

Chapter 11
INTRODUCTION TO LINUX
LINUX- THE NEW GENERATION OPERATING SYSTEM
HISTORY OF LINUX
HOW IS LINUX DIFFERENT?
LINUX V/S OTHER OPERATING SYSTEMS
WHAT IS INCLUDED WITH LINUX?
WHO USES LINUX?
INSTALLING LINUX

146

Chapter 11: Introduction to Linux

Linux, a freely distributable, independent Unix clone, is the latest


operating system being used by thousands of people for a variety of
applications. And has all the features that you would expect from any
operating system that include true multitasking, virtual memory and
TCP/IP networking support.
Linux is mostly running on Intel x86 machines. However, it is also
available for a variety of 32-bit, 64-bit and SMP hardware platforms
such as the SPARC, DEC Alpha, and Motorola PowerPC. Linux blows
the competition away in comparison with other Operating Systems.
Benchmarks have always showed Linux far ahead of the rest of the
Operating Systems. And today many prefer Linux on their machine
instead of other OS.

Linux was created originally by Linus Torvalds; considered as the


father of Linux. But the present version of Linux has been made
possible only with the help of thousands of programmers who have
worked round the clock, over the Internet without expecting any
returns. Although the exact date and time of the start of Linuxs
development is not too clear, development did begin as early as July
1991. Originally started as a hobby project, it was inspired in turn by
Minix, a small Unix system. The very first discussions on Linux can
still be traced to the comp.os.minux Internet newsgroup.

The official version of Linux was launched on October 5, 1991 as


Version 0.02. This could run bash (Unix shell) and GCC (C Compiler)
but nothing more. Since then, more stress was laid on the development
of the Linux corethe kernel. This continued until Version 0.10, by
which time floppy drive support and some other small bugs were
sorted out. The next Linux version number was 0.95 that arrived in
March 1992 when more apps started running on Linux. By December
1993, Linux was in version 0.99 and was rapidly moving towards
Version 1.0. Finally, Linux 1.0 was released in March 1994. And since
then there has been no looking back.

NEW FEATURES

Version 2.0 was released in June 1996, and includes enhanced


support for symmetric multiprocessing and portability across multiple
p l a t f or m s. I t a l s o i n t r o d u c es p e r f or m a n ce a n d a l g o r i t h m i c
improvements, enhanced networking, improved memory management,
NFS read caching, increased support for real-time applications, an
expanded set of supported hardware, graphical kernel configuration,
and new kernel modularity features.

This operating system is now coming with development software, text


editors, Internet and graphics manipulation toolsall for free.

Chapter 11 : Introduction to Linux

147

The short technical explanation is that Linux is a multi-user, multitasking operating system that runs on many platforms, including
Intel processors, 386 and higher. It implements a superset of the
POSIX standard. Linux inter-operates well with other operating
systems, including those from Apple, Microsoft, and Novell.
This complete operating environment includes:

hundreds of programs including compilers, interpreters,


editors and utilities

tools that support connectivity, including Ethernet, SLIP and


PPP, and inter-operability
reliable, production releases of software, as well as cuttingedge development versions

a development team located around the world working to


make Linux portable to new platforms as well as supporting
a user community as diverse in needs and location as the
development team itself

One thing differentiating Linux from many other operating systems is


the priceits free. That is, it can be copied and redistributed without
having to pay a fee or royalty to anyone. However, there is more to the
issue of Linux being free than price. Being licensed under the Free
Software Foundations General Public License means the source code
for Linux is available to anyone. The last five years of Linux development
have shown the importance of this freedom; it has resulted in an
amazing level of involvement for thousandspossibly hundreds of
thousandsof people around the world.
This freedom has made it possible for hardware vendors to develop
drivers for their particular devices without having to obtain an
expensive source code license or sign restrictive non-disclosure
agreements. It has also made it possible for people needing a realtime operating system to slide a small real-time kernel under the
Linux kernel. And it has helped computer science students around
the world to see the insides of a real, commercial-quality operating
system.

WHAT IS A LINUX DISTRIBUTION?

While Linux itself is freely available on the Internet, various vendors


have built what are called distributions, which can be thought of as
packaged versions of Linux. They include the Linux kernel, networking
support, hundreds of utility programs, development software, a
graphical interface, and many graphics utilities, and much more. In
addition, these distributions include some sort of installation software
and may optionally include support.
Some distribution vendors make their complete distribution, including
installation software, available for free on the Net. Others elect to

148

Chapter 11: Introduction to Linux

make their installation software proprietary and sell the package with
support for a nominal fee.

This doesnt mean there is nothing left to buy or wish for, but it does
mean that if, for example, you are a software developer, theres not
much you need to buy in order to turn Linux into a reasonably
effective development platform.
One of the more common things people want to do is connect to the
Internet. Everything you need to connect to the Net is available for
Linux for free. In fact, Linux can be turned into a first class Web
server with a software available for free.

Linux is based on the POSIX operating system standard, which was


derived from Unix when Unix was still a product of Unix Software
Laboratories. Today, Unix is available to the OS vendors only when
their software passes a series of tests and they pay a licensing fee.

Unix is compatible with Linux at the system call level, meaning most
programs written for either Unix or Linux can be recompiled to run on
the other system, with little or no modifications. While traditional
Unix runs on more types of hardware than Linux, it has paid the price
of over 25 years of baggage to make this possible. That means Linux
will run faster than Unix on the same hardware. Moreover, Unix has
the disadvantage of not being free.
MS-DOS, like Linux, has a hierarchical file system. But it only runs
on x86-based processors, does not support multiple users or multitasking, and it is not free. Also its interoperatility with other operating
systems is poor and it does not include networking software,
development programs, or many of the utility programs included with
Linux.
Microsoft Windows offers some of the graphics capabilities of Linux
and includes some networking capabilities, but it suffers all other
handicaps of MS-DOS.
Windows NT is available for the Digital Alpha, as well as x86 processors,
but it suffers many of the disadvantages of Windows. It has had much
less time in the field (meaning less time to work out bugs), and it has
a rather large price tag attached to it.

Apples operating system for the Macintosh runs only on the Mac. It
also suffers from a lack of development tools and less-than-smooth
interoperability with other systems.

When you get Linux, you get everything. That is, everything you would
expect to be included with an operating system, and more. Each

Chapter 11 : Introduction to Linux

149

Linux distribution includes hundreds of packages offering a full and


rich set of utilities, connectivity tools, and a development environment.
Here is a short list to give you the general idea:

Development software including compilers, assemblers, and


debuggers
Text editors and text formatting programs
Usenet news readers and e-mail agents

World Wide Web development tools, Web servers and browsers


Graphics creation and manipulation tools

For example, Linux can be used by a small ISP. To offer this sort of
service you need:

Internet connectivity

PPP and possibly SLIP connectivity

Multi-port, dial-up service


Usenet news
Mail routing
Web server

Online backups

Most of these capabilities are inherent in Linux. The others come with
the hardware needed to support the capability.

PPP and SLIP are integral parts of Linux. Their support and the
number of channels supported are configuration options when you
build the Linux kernel. Support for regular Unix login/password
security is also available.

Usenet news and Internet mail are also included. The software to
support news includes the standard systems available on Unix
platforms. INN seems to be the most popular. Mail is handled by
sendmail for most systems. While not as capable, smail is also
available and may be a better fit for low-end configurations.

Various Web servers are also included with Linux. Finally, backups.
In order to be a respected ISP you need to offer continuous service and
you cant lose your customers data. After all, thats why they pay you.
Linux includes the standard Unix utilities to do backups (tar, cpio,
and backup/restore). There are also commercial products offering
additional capabilities.
This doesnt mean Linux comes with every application you need to
run your office or your entire business. However, while it may not be
included, it may be available. For example, databases, word processors,
spreadsheets, and sophisticated graphics programs are available for
Linux. You will see names like Applixware, Corel, and Empress in
the Linux camp when you look for these sorts of applications.

150

Chapter 11: Introduction to Linux

Linux is replacing the traditional Operating system like Unix, Solaris


1 and 2, HP-UX and Operating Systems from Microsoft. In addition,
many people have started using use Linux on their computers at
home.
Other places Linux has significant market penetration is in Web
servers and as the operating system of choice in universities. Also,
many individuals whove realized the need to learn Unix for career
advancement have decided to use Linux on their home computer as
a training tool.
Linux is also becoming popular in embedded and turnkey applications,
including Internet firewalls, routers, and Point of Sale (POS) systems.

Linux doesnt need the latest, fastest, hardware to run on. Hardware
that you brought last year or may be the year before, and are now in
the process of replacing can happily run Linux. Your ancient 386 and
486 can become routers on your network. The Pentium 100 that you
are about to junk could perhaps become your mail server. Moreover
another biggest thing about Linux is that it almost installs by itself.

A 386 with 8 MB of RAM will do, but a 486 with 16 MB of RAM


is a good start.

A full install of Red Hat Linux 6.x will take about 540 MB
but if you are short on disk space, you can also get away with
around 100 MB.

You will naturally need a CD-ROM drive. Linux recognizes just


about every CD-ROM drive, so anything with a speed of 2x
upward should do.
If you plan to run X Windows, youll need a VGA display, but
if you are just looking at running Linux as a text based
workstation, or as a server, just about any display (even a
CGA) will do just fine.

To integrate Linux into a network, youll want an Ethernet


card. Linux has built-in support for most popular Ethernet
cards (both ISA and PCI), so anything you can lay your hands
on should be acceptable.
Finally, you should ensure that you have a serial port for
communication, a parallel port for printing, and a serial port
(or a PS/2 mouse port) for mouse. All are optional, though you
will need a mouse if you intend running X Windows.
If your PC does not support booting off CD-ROM, youll also
need two blank 3.5" diskettes. Ensure that your PC allows
booting off diskettes, you may have to enable this in the
system BIOS.

Chapter 11 : Introduction to Linux

Now you are almost ready to start

151

Earlier versions of Linux could be installed on your hard disk without


partioning it, you could install it in your DOS partition. It was a plus
point in those days as there was very little performance difference
between this kind of install (called a UMSDOS install) and a native
Linux partition. But todays native Linux file system offers such
tremendous performance and security advantages that it no longer
makes sense to do an UMSDOS install. Red Hat Linux does not offer
a UMSDOS installation option for this reason.
This means that you need to carefully consider this issue. In order to
install Red Hat Linux on your computer, you need to create new
partitions. Most of you will have your hard disks partitioned for Win
95 or a similar OS. This implies you need to shrink the Win/DOS
partition to make room for the Linux partition, or make available a
separate hard disk for this purpose.
There are two ways of installing Linux :

you can either install it with another operating system with a


dual-boot option.
you can install it alone

For installing Linux only, you should have at least a 1.2 GB hard disk.
For installing it with a dual-boot option, the size depends upon the
space requirements of the other operating system. For instance, if
you want only DOS for the second partition, you dont need more than
100 MB of space.

The simplest possible way of starting the installation process is to


insert the CD-ROM into the drive and booting off it. This requires that
your PC can boot off a CD-ROM and that the option is enabled in the
BIOS (most new Pentiums allow this).
If you have a SCSI bootable device, then, youll need to create the
Linux boot and supplement disks before you start the installation. To
make the disks, go to the \IMAGES directory of the CD-ROM and run
makedisk.bat file. Keep two 1.44 MB floppy disks handy.

You will be asked if you are using a color monitor. Even if you have
a monochrome monitor, select yes because Linux will run in greyscale
mode. This is followed by a screen asking you to specify the keyboard
type (select default), and the type of media that contains the packages
to be installed (selectCD-ROM).
You are then asked to specify whether youre upgrading or doing a
fresh install. Choose the latter. The next prompt is an important one.
It asks whether you have any SCSI adapters? If you have a SCSI
bootable device, then you will need the Linux supplement disk. If you
have an Iomega Zip drive installed, Linux recognizes it as a SCSI
device. Dont connect the zip drive now. You can always set it up later
after the installation.

152

DISK PARTITIONING

Chapter 11: Introduction to Linux

The next part deals with disk partitioning, and is slightly tricky. You
have to select a partitioning utility to set up the mount points.
Choices available are Disk Druid and Linux fdisk. Both work fine, but
we used Disk Druid. Whatever be the number of partitions you create,
youll always need to create a Linux swap partition and a Linux native
partition. All partitions are created by using the add button in Disk
Druid. Keep your swap partition to 64 MB if you have 16, 32, or 64
MB of RAM. Use the tab key to navigate through the various buttons
in Disk Druid utility.
After creating the Linux swap partition, note down the remaining
hard disk size. The size specified here is 1 MB more than the actual.
When you add partitions, you will be prompted to enter the partition
size. Whatever be the number of partitions, ensure that the total disk
space that you specify is 1 MB less than what Disk Druid displays.
Press the F12 key to save changes and continue. You will be prompted
to select the mount point. This is where all the Linux boot files will be
located (Linux native partition). If it doesnt prompt you for it, then
highlight the Linux native partition and select the edit button in Disk
Druid. Enter a / when it asks you to specify the mount point and
continue.

The next two options prompt you to format the swap space and the
Linux native partition. Both screens have an option to check for bad
blocks while formatting. If you have a new hard disk, you can disable
this option, as checking for bad blocks takes time. If you have an
older hard disk, and are not sure whether it has bad blocks or not,
you should enable this option. Also, note that at this point, you can
switch between screens showing the log file, or the Linux shell prompt
by pressing Alt+F1, F2, and F3. These can be useful if something goes
wrong with the installation, and youd like to check the log file for
errors, or to go to the Linux shell prompt to check for installed
directories.

INSTALLING SOFTWARE COMPONENTS

Next comes installing the software components. The installation


program displays a dialog box showing the list of components. Use
the spacebar to select or deselect an option. You can select from the
various packages, or select all by going to the bottom of the list and
selecting the everything option. Installing everything takes slightly
more than 500 MB of space. Press continue and Linux starts copying
all the files to the hard disk. This process takes about 20 minutes.

After all the files are copied, Linux will detect your mouse, display
adapter, and the monitor. In each case, it displays a list of devices to
choose from. Select from the list of devices that pop up. If youre not
sure of which mouse and monitor you have, select Microsoft compatible
mouse, and generic monitor options. When it asks you to set up the
default resolution and color depth settings, select dont probe (selecting

Chapter 11 : Introduction to Linux

153

probe may halt your system). You will also be prompted to enter the
video memory and the clockchip present in the display. Enter the
video memory, and leave the clockchip setting to no clockchip. Next
enter the mode you want to run it in. This is where you enter the
resolution and color depth. Choose the one your display adapter
supports. All these settings are required to run X Windows. If these
settings are not correct, you can always reconfigure them after the
installation. For this, login and type Xconfigurator (X should be
capital). Same prompts for setting your display card and monitor will
come up again.

CONFIGURING LINUX

You have now completed the basic installation of Linux. Next comes
th e configur ation p art. Fir st on the agen da is the n e twor k
configuration. Linux automatically detects any network cards in your
machine. If theres a PCI Ethernet card, Linux automatically detects
it and continues to the TCP/IP configuration. But if theres an ISA
card, you will need to supply a base address to it before proceeding.
Commonly used base address is Ox300. In the TCP/IP configuration,
you have to specify the IP address, netmask, default gateway, and the
primary nameserver. If you are setting up a fresh network, then use
the reserved IP address range meant for LANs192.168.1.x. It makes
sense to give this machine the IP address 192.168.1.1. If this is also
your primary gateway to the Internet, then set the Gateway address
to the same IP address.
Then you are prompted to enter the domain name, and the host name.
If you have a domain name registered, you can enter that here. For
example, we used cmil.com as the domain name, and <computer
name>.cmil.com for the host name.

There are only a few more steps left. You have to configure the time
zone. Choose Asia/Calcutta from the list as that is the only one
available for the Indian subcontinent. Linux then prompts you to
start the services, and gives you a list of the ones its going to start.
Leave it to default and continue.

Now comes printer configuration. If you have a printer, enter the


name of the queue, and the spool directory (leave to default). Select
the type of printer from the given list. You will now need to supply the
root password. This should be at least six characters long.
Finally, it asks you to specify where Linux will boot from. Select
master boot record. Linux will reboot and prompt you to enter the
username and password. Enter username as root and the password.

Appendix A
THE BOURNE SHELL
THE BOURNE SHELL
PRECEDING A COMMAND BY ITS PATH
COMBINING COMMANDS
SHELL VARIABLES

156

Appendix - A

This chapter introduces the agency that sits between the user and
the UNIX system. It is called the shell. All the wonderful things that
you can do with UNIX are possible because this agency can
understand so much by seeing so little code. It is more like an
efficient secretary who understands your directives from your gestures,
and carries them out by specially devised means which you neednt
know. Like the command processors of other operating systems, the
shell process the instruction that you issue to the machine. But the
shell is much more than a command processor, and a through
understanding of its features is necessary if you are to exploit the
power that UNIX offers.
The Bourne shell, named after its founder steve Bourne. It is one of
the earliest shells that came with the UNIX system, and also one that
is most widely used. There are other shells that feature in every UNIX
system today. Notable among them are the C shell, a product from
the University of California. Berkeley and the Korn shell from David
Korm of Bell Laboratories. The C shell has an advanced user
interface with enhanced features. The Kom shell is the most modern
shell available, and is likely to become the industry standard.

THE BOURNE SHELL


sh Command

If you list out the /bin directory (/usr/bin in Release 4), you will see
an executable program named sh. This is the Bourne shell. The C
shell and the Korn shell, if present will have the names csh and ksh,
respectively. The shell is the sleeping beauty of the system, even
though it acts as your interpreter when you try to talk to the machine.
When you issue an instruction, i.e. command, the shell is the first
agency to acquire the information. Before executing the command,
it sees whether the command line is in a form which the system can
understand. If it is not , then it processes the request to recreate a
simplified command line. It then leaves the job of command execution
to the kernel.
The shell is really a UNIX command a program that starts when you
log in, and terminates when you log out. But unlike other UNIX
commands, it is there all the time, indicating its presence by the
familiar $ prompt. This point has to be taken seriously because the
shell program starts executing the moment a user logs in. It
resembles the role played by COMMAND. COM in MSDOS, through
the capabilities of the shell far outweigh those of COMMAND.COM.
The unique thing about the shell is that, while it is technically a UNIX
command itself, its main job is to accept and interpret user requests,
i.e. other UNIX command.
One of the functions of the shell is to wait for input from the user.
Anything keyed in through the keyboard, and at the $ prompt, is

Appendix - A

157

actually the input to the sh program. With this input, it performs


a series of processing tasks, interacting with the kernel when
necessary. After the job is complete, it returns to its waiting role, to
start the next cycle . The following activities are typically performed
by the shell in each cycle :

(a)

It issues the $ prompt, and waits for you to enter a command.

(c)

The command is then passed on to the kernel for execution,


and the shell waits for its completion.

(b)

(d)

After a command has been entered, the shell scans the


command line for some special characters (the focus of
attention in this chapter) , and then rebuilds the command
line after processing is complete.
The $ prompt appears, and the shell waits for you to enter the
next command.

When there is no input from the user, the shell is said to be sleeping.
This is indicates by the $ prompt, meaning that you are now free to
enter any text. It wakes up whenever a user enters some characters
through the keyboard , and presses the <Enter> key (sleeping,
waiting and waking are accepted terms in UNIX parlance). The
productive work of the shell begins after it has accepted the
characters that are keyed in.

So what does the shell do with this input ? It first scans the command
line, and processes it in a number of steps. During the scanning
operation, it looks for certain characters which have a special meaning
for it. Because it permits abbreviated command lines (like the use of
* to indicate all files, as in rm*), the shell has to make sure the
abbreviations are expanded before the command can act upon them.
This is important because these special characters usually mean
nothing to the command. It rebuilds the command line at every step,
and when all processing is complete, it passes on the processed
command line to the kernel for execution.

PRECEDING A COMMAND BY ITS PATH

A command runs in UNIX by executing the file containing the


command. When you specify the date command, for example, the
shell has to locate the date program (or rather the file named date)
from a predetermined list, and then execute it. But if you know the
location of a particular command, you can precede its name with the
complete path. Since the date command resides in the /bin
directory, you can also use the complete (or absolute) pathname :

$ /bin/date

Tue Apr 2 20:11:11 EST 1991


$

You normally dont need to do that for files residing in the /bin and
the /usr/bin directories, but if you are to execute programs residing
in some other directory which is not current directory, then the
pathname must be specified.

158

Appendix - A

So far you have been executing commands separately; each command


was first processed and executed before the next could be entered.
But UNIX allows you to specify more than one command in the same
command line. Each command has to be separated from the other by
a ; (semicolon). This delimiter can be used to separate the chmod and
is commands :

$ chmod +rw note : Is -l note

In one shot, you can assign read and write permissions to the file
note, and then see with the Is command whether the action has been
performed. You can combine a number of such commands in this
way, using the : to separate. If the sequence of characters continues
beyond the width of the terminal, you can comfortably continue
entering the input without hitting the <Enter> kry. All you will be
seeing is that the line has been carried over to the next, but that wont
affect the performance in any way.

Like every programming language, the shell offers the facility to


define and use variables in the command line. These variables are
called shell variables, and have a couple of unusual features. No type
declarations or initialization are necessary before you can use them.
Shell variables are assigned with the = operator, but evaluated in a
different way. Unlike the variables used by programming languages,
they are evaluated by prefixing the variable name with a $. A simple
example will clear things up :

$ x = 37
$ echo $x
37
$

All shell variables take o the generalized form variable = value. They
are of the string type, which means that the value is stored in ASCII
rather than binary format. When the shell reads the command line,
it interprets any word preceded by a $ as a variable, and replaces the
word by the value of the variable. There must not be any spaces on
either side of the = operator, because the shell treats spaces as the
delimiter of arguments. You cant assign multiword strings to a
variable in this way :

$ msg=You have mail


have : not found
$ echo $msg
You
$

Appendix - A

159

The first word is assigned to the variable msg, and then the shell has
attempted to execute the second word. The shell has a feature of
making an assignment before the execution of a command in the
same command line, which you will see later, have is obviously not a
command, so the shell responds accordingly. To assign multi-word
strings to a variable, you should quote the value :

$ msg=You have mail


$ echo $ msg
You have mail
$

or alternatively, you can escape the meaning of the space character;

$ msg=You\have\mail
$ echo $ msg
You have mail
$

This highlights an important point, viz the special meaning of the


space character. This character and the tab are used by the shell to
delimit commands and their arguments. When multiple space or
tabs separate words in the command line, the shell compresses all
such occurrences to a single occurrence. When you precede the
space character with a\, the shell takes it to mean that the character
is not to be used in its usual sense, but treated literally.
How are shell variables useful ? when used in an intelligent manner,
they can speed up your interaction with the system. Suppose you
have to use the absolute pathname/usr/kumar/progs/ data several
times in a session. You can easily assign this pathname to a variable,
and then use its short-hand representation :

$ pn=/usr/kumar/progs/data
$ echo $pn
/usr/kumar/progs/data
$ cd $pn
$ pwd
/usr/kumar/progs/data
$

Variable are extensively used in shell programs where they have a


wide application. Tehy can be used to generalize filenames, options,
expressions, addresses or any other argument to a command. Thus,
it is quite permissible to define.

$ files=unit01 unit02
$

and then use the value as the arguments to the wc command :

160

$ wc $ files
436
892
1328
$

Appendix - A

6463 37986
8273 48420
14736 86406

unit01
unit02
total

A shell variable can be used to replace even the command itself. You
can assign the above command itself to a variable count . When a
command is assigned to a variable, the variable should be evaluated
(i.e. the command executed) by simply specifying the $-prefixed
variable as the only word in the command line:

$ count=wc $ files
$ $count
436
6463 37986
892
8273 48420
1328
14736 86406
$

unit01
unit02
total

Appendix B
ENVIRONMENT IN UNIX
LEARNING ABOUT YOUR ENVIRONMENT
SHELLS & YOUR ENVIRONMENT

162

Appendix - B

THE LOGIN SHELL

When you login your UNIX system, youre immediately thrust into
your login shell. We discussed logging in your system and setting up
a password, we were detailing how you were configuring your login
shell. This information is usually contained in the file /etc/passed,
as is login information for all the users on your systems. This file is
organized by user, with each line, containing the basic information
regarding every user. name, login ID, and so on. The final field in your
line lists the shell you want to run after logging in. Again, this isnt
terribly important to your daily UNIX usage, but it shows that every
aspect of UNIX usage is governed by a shell of some sort.
Based on this information the UNIX system then launches your shell,
with information contained in the .profile file for C shell users, the
.login and .cshrc files; for Korn shell users the .kshrc file.

As discussed UNIX features several shells, and you have the power to
change shells when you want. As a new UNIX user, one of the most
useful aspects of your shell is its flexibility as exemplified by its
extensive use of variables.

VARIABLES

UNIX uses variables in a similar sense, it allows the user to define


information with both a name and a value that may change over the
course of time. Variables can be used both by the shell and by other
UNIX programs. These variables are contained in the .profile file or
the .login file, which we mentioned briefly earlier. This file definers
what terminal you are using , what your system prompt will be if you
dont like the default, as well as any applications you want to run
immediately after logging in.

When you initially login a UNIX system, many of the variables have
been set by the system automatically. However, many others have not
Configuring these variables is up to you:

$ VARIABLEENAME = VARIBLEVALUE

Where VARIABLENAME is the name of the variable and


VARIABLEVALUE is the value of the variable.
Here will discuss how the shell uses variables to set up a personalized
environment and how you can change these variables. Your particular
system may not contain all these variables.
Variable

Meaning

DISPLAY

Used by the X - Window System to identify the


display used by X applications.

CDPATH

Assigns directories searched via the cd command.

Appendix - B
EDITOR

HOME

163

Lists your text editor. Some applications


a ut om a ti c a l ly lo a d a t ex t e di t or i n c e r t a i n
situations, and this variable tells the application
the editor to load.
The full name of your login directory. This is the
directory where your personal files are stored.

LOGNAME

Your login name.

MANPATH

The directory containing your online-manual


pages.

MAIL

PAGER
PATH
PS1

The full name of the directory containing your


electronic mail.

Defines the program used to page through files.


Some applications summon a UNIX command to
scroll through a text file.
The directories where the shell searches for
programs.
Define your prompt, which can be changed .

SHELL

Your current shell.

TZ

Your current time zone, usually in terms of


Universal time.

TERM

USER

VISUAL

Your terminal type. This determines how your


UNIX system interprets keyboard input and sends
output to your screen.

Your login name, like LOGNAME, above.

Lists your visual text editor, such as vi. Some


applications automatically load a text editor in
certain situations, and this variables tells the
application the editor to load.

Before you start messing with your variables, you probably should
know a little about your current variable. To generate a list of your
current shell variables, use the command set:

$ set CDPATH = :/users/home/:/users/kevin


HOME = / users/kevin
LOGNAME = kevin
MAIL = /users/kevin/mail
PATH = /usr/bin
PS1=:
PS2 = . .
SHELL =/usr/bin/sh
TERM = vt100
TZ = CST6CDT

C shell users would use the command setenv or env:

% setenv

164

CDPATH=:/user/home/:/users/kevin
HOME=/users/kevin
LOGNAME=kevin
MAIL=/users/kevin/mail

Appendix - B

PATH=/usr/bin
SHELL=/usr/bin/sh
TERM = vt 100
TZ = CST6CDT

As with everything else in UNIX case counts. DATA, Data, and


data would be three different variables. The first letter of a
variable must be an underscore (_) or a letter subsequent
characters can be letters numbers, or underscores. The shells
reserved variables are all marked by uppercase letters. Its a
good idea for your to also use all uppercase variable.
To use a variable or a command line, you must preface it with
a dollar sign ($). This tells the shell that youre invoking a
variable; that is you want the value held in the variable and
not a command-line argument, as in this command line:

$ echo $HOME
/users/home

If you want view a specific variable at any time, use the echo
command along with the name of the variable:

$ echo $HOME
/user/home

Setting Your Own Shell Variables

You arent limited to the variable less define by the system: you could
set up your own variable and refer back to them. This process is called
assigning variables in UNIX parlance.

You can assign a variable at any point in a UNIX computing session,


To use an example: Lets say youre working on a giant data-research
project, and you want to save all files to the directory /users/kevin/
data/research/1995stuff. Thats quit a lot to type every time you
want to call or save a file. In this instance, assigning a variable to
store this long pathname would definitely be a good idea. Do so by
typing the following:

$ DATA = /users/kevin/data/research/1995stuff

Any string to be saved as a variable must be enclosed in quotation


marks. If we wanted to list all files in the subdirectory /user/kevin/
data/research/1995stuff, we would type the following:

$ ls $DATA

Appendix - B

Exporting Your Variables

165

When you create a variables. Its by definition a shell or local variable,


which means it is available for use by the shell, not necessarily to
your UNIX application. In these instances youll want to explicitly tell
the shell to export its variables to all programs. Do so with the export
command:

$ export DATA

You could export multiple variables with the same command:

$ export DATA VARIABLE2 VARIABLE3

This command makes the variable DATA available to all programs.

If youre planning on exporting every variable you assign, you can use
the set command with the -a option to tell the shell to automatically
export every assigned variable.

$ set -a

Removing Variables

After a variable serves its purpose, its a good idea to remove it, using
the unset command. The following command removes the variable
DATA:

$ unset DATA

Your environment, essentially, is a collection of all your variables, as


defined by your system. These variables would not include any
assigned variables. To see a listing of your environment, use the env
command.

$ env
EDITOR = vi
ED = vi
HOME = /user/kevin

LOGNAME = kevin
MAIL = /users/kevin/mail
PATH = /usr/bin
PS1 = :
PS2 = ...
SHELL = /usr/bin/sh
TERM = vt100
VISUAL = vi

166

SPECIFYING YOUR TERMINAL

Appendix - B

UNIX systems are built around a server, which distributes information


around the network. Each user sits at a terminal which can be a
dumb ASCII terminal, a UNIX workstation, or a PC running connective
software.

To function properly, the server needs to know exactly what kind of


terminal is attached theres no mechanism for the UNIX system to
check the terminal and make the configurations automatically. Some
UNIX programs-especially programs like vi-also need this information.
Especially if they take over an entire screen. The terminal type is
specified with the TERM variable. Popular terminal types include
VT100, VT200, and ANSII.

Customizing Your Terminal

Hardcore UNIX users lose to fiddle with their systems, which leads to
the 70 or options, available just for terminal configuration alone
when using the stty command.

$stty echo

SPECIFYING AN EDITOR

Most thoughtful system administrators will have a text editor specified


in a .profile file. This because some UNIX applications call upon a
text editor for input, and these applications make a call to an editor
variable, rather then defining a specified editor.

EDITOR =vi
ED=vi
VISUAL=vi

SETTING YOUR PATH

A path is the series of directories that the shell searches to find a


command. For example, when you use the set command, the shell
looks through a predefined series of directories in search of the file
that makes up the set command .

e.g.

PATH =/user/bin

With PATH defined like this, the shell will not go to any other
directories in search of command. However, the PATH statement may
be the culprit when you issue a command that you know exist and
your system report that accompanying file cant be found. If its a
frequently used command go ahead and add the directory to your
PATH statement making sure that you separate the directories with
a colon:

PATH=/user/bin :/bin

Appendix - B

COMMAND SUBSTITUTIONS

167

A Command substitution inserts the output of the program into your


command line. In our example well use date both as a string for use
by the echo command and as input for the echo command. Since the
echo command merely echoes input from the command prompt,
neither example does a whole lot, but it adequately illustrates the
difference.

$ echo date
date
$ echo date
Set Jul 25 12:27:48 CST 2001

That command used in command substitution are enclosed with


accent marks, not single quotation marks. The accent mark is usually
found on the leftmost part of the number line on most keyboards.

Appendix C
C PROGRAMMING
C PROGRAMMING
WRITING A SMALL C PROGRAM
WORKING WITH CC

170

Appendix - C

C Programs - and in fact, most programs in general - usually start in


plain old text files. These text files are created with text editors like
vi or emacs . Once created, C programs must be compiled with,
naturally enough, a C compiler, which is a UNIX command. This C
compiler converts the text file, which the programmer wrote, into
object, or machine, code for your programming platform. Then, object
modules are linked together to make an executable program, a brand
new UNIX command. Once the process is successfully completed, you
can execute this program like any other command you type at the
command line. Being able to create your own command is neat.
However, by writing shell scripts, as we described in the last chapter,
you can do essentially the same thing. In fact, to solve your particular
task, there may already be a UNIX command ready and waiting. So,
from the plethora of UNIX tools, you need to choose what is the
appropriate tool for any given task.

Even if you never write C programs, though, it is important to know


about the process of compiling and linking C program because the
vast majority of UNIX freeware comes in source-code format, which
you must compile to be useful.

FILE NAME AND TYPES

Most C programming files use special suffix to tell what type of file
they are, A few of the most common are listed in table below.
File Suffix

DOS Equivalent

Meaning

.h

.h

C include file.

.c

.o

-c

obj

.asm

a.out

.exe

.a

.lib

.C

.cpp

.cpp

.cpp

.cc

.cpp

.cxx

.cpp

.f

.for

.c++
fox

.cpp
.fox

C program

Object module(compiled
from a.c file)
Assembly code.
Library

Executable ( no one uses


the a.out name ).
C++ file (note uppercase C).
C++ file

C++ or C preprocessor file.


C++ file
C++ file

Fortran program.
Fortan program

Most C programs are stored in one or more files that file end with .C,
like inventory.C and checkin.c for example. When you compile a C
file, the C compiler, cc, creates an object file, usually ending with .o.
The linker ld, then links the .o. file together to make an executable

Appendix - C

171

program. The default name for this program end up with names like
ls,cp, or mv. All of this is controlled by the cc command.

Cc Command

The cc command executes the C compiler, which can compile and link
c programs into executable commands. The myriad of options to cc
controls exactly what the compiler does. We wont cover all of the
many cc options, instead, well introduce the most important ones
and let you read the online manual for cc for the rest, Use the
following command to read the manual pages for cc

$ man cc

We must warm you that youll see a lot of output.

Getting a C Compiler

Many modern UNIX systems dont come with the tools you need to
write your own programs. In that case, youve out of luck unless you
ca n som eh ow ac qu ire o ne. F or m a n y o f us s tu ck i n t h e se
circumstances, theres a nice alternative. The Free Sof twa re
Foundation, creators of emacs, also have created a neat-o free C
compiler. This compiler, called gcc, is available over the Internet
form prep.ai.mit.edu and a host of other sites. The GNU C compiler
is available in source-code from, which leaves you with a chickenand-egg problem: You need a C compiler, the cc program, to compiler
the source to this C compiler, So, youll need to get both the binary
version for your hardware platform as well as the source code.

To, test your C compiler, you can enter the following program:

# include <stdio.h>
main ( )
{
/* main */
/* This is a comment */

printf( This is the famous hello world program.):


printf(It prints out a message:):
printf(Hello world!):
/* main */
}

The program is short, and you can probably type it in using vi or


emacs or another text editor, in under one minute. Type in each line
one at a time, exactly as presented above. If you name the file hello.c,
then you can use the following vi command to start editing the file.

172

$ vi hell.c

Appendix - C

Then in vi, enter in the program listed previously.

After you type in this short program, you can follow through the
following simple steps to create a working executable program from
this C file .

The program you typed in was simple a text file. Theres nothing in it
to make it an executable command C program arent like shell scripts
, so we cant simply mark the text file with the execute permission to
make it a working program. Instead, we need to compile and link the
program. Both steps are accomplished by the following cc command:

$ cc .o hello hell.c

The above command runs the C compiler, cc. The -o option tells cc to
build a program named hello. The hello.c part of the command tells
cc to compile the file named hello.c . The cc command both compiled
and linked the program.
Now, you should have an executable program named hello. You can
execute this program by typing hello at the command line. When you
do, youll see the following output.

$ hello

This is the famous hello world program.


It printer out a message:
Hello world!

Now youre a bona-fide C programmer and ready for a new lucrative


career.

Compiling the Long Way

The cc command first compiled the program into a object module,


then linked the object module to create an executable program, the
file named hello. This is very important if you have more than one file
to compile together into your program. Most C program require a
number of .c files, all of which must be compiled and then linked
together to form one program. One of the main reasons for separating
C programs into multiple files is simply sanity: reading a onemegabyte program in one file is ludicrous. And yes, C programs get
to this size and even much bigger than one megabyte.
To use the long method of compiling and linking we split the tasks
into two steps. First you compile all of the .c files you require. Then,
you link the resulting .o files into your executable program. Since we
have a very small C program typed, well start with that.

To compile hello.c into an object module, a .o file, use the following


command:

cc -c hello.c

Appendix - C

173

If successful, you should see a file named hello.o in your directory.


The .o file is called the object file. Using the ls.l command, you should
see this file:

$ ls -l hello*
-rw-r-r- 1 erc
-rw-r-r- 1 erc

users
users

235 Jul 28 21:11 hello.c

646 Jul 28 21:11 hello.o

The next step is to link object files (usually theres more than one) into
an executable file. To do this, we again use the -o option to cc, but
this time we pass a .o file at the end of the command line, rather than
the . c file we used above:

cc -o hello hello.o

This command links together the file hello.o into the executable
program hello. You can place more than one object file name on the
command line, as in the following example:

cc - 0

hello

hello1.o hello2.o hello3.o

Were not trying to torture you. You need to know how cc operates to
compile a large amount of the freeware youll find.

In normal operation, the cc command executes a number of other


commands under the hood. One such command is cpp. The cpp
command is the C preprocessor. This reads a C program file, a .c file,
and expands any # directives. In the short program listed previously,
the #include directory means to include the file stdio.h. That is, cpp
reads in stdio.h and inserts the contents right at the #include
directive. Most C programs use one or more include files.

These include files are normally stored in /user/include. If you use


the angle brackets, (<) and (>), around an include file name, like
<stdio.h>, this means that cpp looks for a file named stdio.h in the
standard places. of which /user/include is the default. You can also
use quotation marks() around the file name.
All C program are built around the section labeled main( ). The main(
) section is executed when the program starts. Our main() function
has three C program statements, all of which call the printf() function,
which prints out the text between the quotation marks to your screen.
As you can tell, this is not a sophisticated program.
Each \n character passed to printf( ) in our example source code.
Means that a newline character is printed. This starts a new line. If
youre used to a DOS machine, youll note that UNIX uses a newline
character where DOS uses a carriage return and then a newline. The
backslash. \, is used as a special character in C programs. Usually,

174

Appendix - C

a backlash, \, is combined with another character to make a


nonprintable character, such as \n for a newline or \a for a bell.

Using The Cc Command

The cc command uses a number of command-line parameters to tell


it what to do and to allow you to fine-tune the process of building
executable programs from C language text files, The lists of commonly
used cc command-line parameters given bellow.
Parameter

-l directory
-c filename.c
-o program
-g

-O

Meaning

Search the given directory for include files,


as well as /user/include
Compile the file filename.c and build the
object module filename.o Do not create an
executable command.

Name the executable program program.


The default name is a.out.
Compile with debugging information.

Optimize the program for best performance.

Note that you usually cannot mix the -g


with -O(optimize) options. (The GNU C
compiler allows this, but most other C
compilers dont.)

Appendix D
UNIX COMMANDS
SOME BASIC UNIX COMMAND

176

Appendix - D

UNIX is made up of literally thousands of commands and variations.


In the course of the summary, we did not have the change to cover
every command and variation. Here we have the change to cover the
major commands in some details. As always, this doesnt cover every
possible command. We do differentiate between the various shells.
The default is the Boume shell, while csh refers to the C shell, and ksh
refers to the Korn shell. Unless noted otherwise, a command should
work with every shell. Should you require additional information
about these commands [or those we fail to list], refer to the onlinemanual pages or your systems documentation.

alias

Description
Syntax

at

alias namecmd

alias nameemd

Description

Syntax

(ksh)

Performs specified commands at given times, as


long as the commands require no additional input
from you. For instance, you may want to print a
series of long documents at midnight, so you dont
need to tie up the laser printer for hours when
other people may need it. You dont need to interact
with the laser printer at midnight (although you
should make sure its paper tray is filled before
leaving work!), so you can use the at command to
print at midnight.
at [options] job-ids

Options

The system assigns job IDs when you use the at


command.

-l

Lists current jop

time

Obviously, the time when the command should


run. Unless you specify otherwise (with a.m or
p.m. as a suffix), the system assumes military
time.

-r

Description
Syntax

(csh and ksh)

at time

Note-

banner

Display and sets command aliases. Alias by itself


will give a summary of current aliases.

Removes specified job.

Display up to ten character in large letters using


asterisks (*) or number signs (#) depending on
your system.
banner text

Appendix - D

bg

cal

Description

Resumes a suspended job.

Description

Display the current month in calendar form.

Syntax

Syntax

Syntax

Cancel pending printer jobs. You can either specify


the job ID or by printer to be canceled
cancel

cancel ID

cancel printer
Description
Syntax

Options

-u
-v

Description
Syntax

Options

-c filename
-g

-o filename
-O

cd

cal

cal year

Description

cc

bg PID

cal month year

cancel

cat

177

-l library
Description
Syntax

chgrp

Description
Syntax

Combines or display files.


cat [options] filename.
Output is unbuffered

Prints nonprinting characters.


Compiles C language programs.
cc options filename linkoptions

Specify the name of the file to compile to generate


a .o file.
Generate debugging information.

Specify the name of the executable file to generate.


Optimize while compiling.

Links in the given library, e.g. - IX11.


Change current directory to a new directory.
cd directory

Change a files group ID, which is used for the


group access permissions.
chgrp groupname filename

178

Appendix - D

chmod

Description

Change the access permissions on a given file. The


mode is an octal number in the following format:
Number
400

owner has read permission.

100

owner has execute permission

200
040
020
010
004
002
001

group has read permission

group has write permission

group has execute permission


world has read permission

world has write permission

world has execute permission

chmod mode filename

chown

Description
Syntax

Options

cp

owner has write permission

Add together the number for the permissions you


want For example 423 means that you the user
can read the file users in your group can write the
file and the rest of the world can write and execute
the file.

Syntax

compress

Meaning

-h

change the ownership of a given file.


chown owner filename

Change the ownership of a symbolic link

Description

Compresses a file (of files), creating filename Z

Description

Copies the contents of one file into another file.

Syntax

Syntax
Option

Makes sure you dont overwrite existing file.

-r

Copies entire directory

Description
Syntax

cp [option] filename newfilname

-i

-p

crontab

compress filename

Retains existing permissions.

Tells cron to run a set of commands at specified


times.
crontab filename

Where filename is the name of a crontab file.

Appendix - D

csh

Description
Syntax

date

Description
Syntax

Options

179
Starts the C shell.
csh

Display current date Or, if you have superuser


status can be used to set the system date and time.
date [ date ]

mmddHHMMMMYY

Set month(mm), date(dd), Hour(hh),


minute(MM), and year(YY).

diff

Description
Syntax

Options

Ignores blanks at the end of line.

-e

Creates a script for the ed editor to make filename1


the same as filename2.

Description
Syntax

Generates a context diff.

Display how much disk space is used by a directory


(and all its subdirectories), in blocks(usually 512
or 1,024 bytes each).
du options directories

Options

du options filename

-a

Display all information.

-s

Silent mode. Display only totals

-r

echo

diff options filename1 filename2

-b
-c

du

Compares two files

Description
Syntax

env

Description
Syntax

Options

Reports on file directories du cannot open.

Echoes text to standard output.


echo text

Display the current user environment variables


with their values.
env [options]

ENV=VALUE

Sets environment variable (ENV) to VALUE.

Description

Quits the current session.

exit

180

file

Appendix - D

Description
Syntax

find

Description
Syntax

Options

grep

-print

Description
Syntax

Options

find/ -name filename -print


Print the result of the search.
Searches files for a pattern.

grep options pattern filenames

-l

Lists only filename that have matching lines.

-v

Description
Syntax

options

-n

Description
Syntax

Ignores case.

Lists each matching line with its line number


Lists lines that dont match.

Display the beginning of a file The default is ten


lines.
head filename

Specify the number of lines to display.


Display previous command lines. Used with the C
and Korn shells.
history

jobs

Description
syntax

kill
In

Finds a file.

Only displays the number of lines that match.

-n

history

file filename

-c
-i

head

Describe file type of given file.

Display all current jobs


jobs

Description

Kills a current process by ID number.

Description

Links two or more files.

syntax

Syntax

Options

-s

kill process.id

In filename1 filename2

Creates a symbolic link.

Appendix - D

Ip

Description

Syntax

Options

lp filename

Copies the file before sending the request

-m

Sends a message to the user when the file is


printed.

Ipstat

Description
Syntax

Options

-d

Description
Syntax

Specifies a printer other than the default printer.

Returns the status of print requests.


lpstat options

Copies the file before sending the request.


Lists the contents of the specified directory. If no
directory is specified the contents of the current
directory are listed.
Is names

Options

where names refers to filenames or pathnames.

-a

Lists all contents, including hidden files.

-l

Lists the contents of a directory in long form.

-d
-m
-q
-r
-t

make

Sends a print request to a printer. Can be used to


print multiple files with one request. On some
systems, you may need to use the lpr command
instead.

-c

-d

Is

181

-1

Description
Syntax

Options

-f makefile

Lists only the name of the directory, not the


contents.
Lists the contents across the screen, separated by
commas.
L i st s con t ent s wi t h no n p r in t i n g c h a r a c te r s
represented by a question
mark(?)
Lists the contents in reverse order.

Lists the contents in order of time saved, beginning


with the most recent.
Lists contents one entry to a line.

Builds program from a set of rules stored in a


makefile.
make options targets

Use makefile instead of file named Makefile for


makes rules.

182

-n
-s

man

Description
Syntax

mkdir

Description
Syntax

Options

more

-m mode

Description
Syntax

Options

mv

-c

Description
Syntax

Appendix - D

No execute mode, Only print out command, dont


execute them.
Silent mode. Dont print out and commands make
executes.
Display the online manual page for a command.
man command

create a new directory.


mkdir dirname

Where dirname refers to the name of the new


directory.
Specifies the mode of the new directory
Display all or parts of a file. Type q to quit,
Spacebar to continue.
more filename

Clears the screen before displaying the file.


Move a file or multiple files into another directory
or to a new name in the current directory.
mv filename directory
or

Options

-f
-i

news

Description
Syntax

mv filename newfilename
Moves file without checking for confirmation in
case of an overwrite.
Prompt users if a action would overwrite an existing
file.

Display all news items distributed substituted


system wide.
new

Options

news newsitem

-a

Display all of the news items.

-s

Display a count of all of the news items.

-n

Display the names of all of the news items.

Appendix - D

nice

Description
Syntax

-n

nohup

Description
Syntax

page or pg

Description
Syntax

Options

+n

pr

+/string

Where command refers to the command to execute


nicely.
Specifies n as the decrement in priority. The default
is 10.

Keep a command running even if you log off the


system.
nohup command

Display a file one page at a time.


pg filename

Screen the display at the number n.


Searches for the string

Description

password

Description

Prints a file or files to the default printer.

Syntax

Syntax

Options

passed user

pr filename | lp

-d

Double-spaces the text.

-l

Sets the page length

-h text

ps

Runs a command nicely, by giving it a very low


priority.
nice options command

Options

passed

183

-w
Description
Syntax

Options

-e
-f

Prints the header text at the beginning of the


output.
Sets the page width

Returns the status of all current processes.


ps

Display expanded information about all current


processes.
Display full information about processes.

184

Appendix - D

pwd
rcp

Description

Return the current working directory.

Description

Copies files to and from remote systems.

Syntax

Syntax

resume

Description
Syntax

rlogin

Description
Syntax

Options

rm

rcp hostl:filename host2:filename


Stars a suspended job.
resume PID

Logs in to a remote system.


relogin hsotname

-l username

Remotely login under the new username.

Description

Removes files

Options

-f

rmdir
set

pwd

-i

Removes files without verifying action with user.


Removes files after verification from user.

Description

Removes a director.

Description

Returns the value of all current environment


variables.

Syntax

Syntax

rmdir directory

set

setnv

Description
Syntax

Sets an environment variable (Used only with C


shell).
setnv variable newvariable

spell

Description
Syntax

Options

-b

+s filename

Returns incorrectly spelled words in a file.


spell filename

checks for spelling based on British usage.

Creates a sorted file (filename) of correctly spelled


works.

Appendix - D

Stop

Description
Syntax

stty

Description
Syntax

Options

tabs

-a

Description
Syntax

Options

185
Suspends a currently running process.
stop PID

Sets your terminal configuration and options.


stty

Display current options.


Sets the tab setting.
tabs

-filename Insert tab information in the file filename.

tail

-n

Description
Syntax

Options

-n

tar

Description
Syntax

Options

Sets tab every n characters.

Display the final ten lines of a file.


tail filename

Specifies the number of lines form the end of the


file to be displayed.
Archive files to tar files, often on back tapes.
ta options filename

Create a new tar archive.

Print out a table of contents.

Extract files from within the tar archive.

f filename Write archive to filename often /dev/tape.


v

telnet

Description
Syntax

uncompress

Description

unset

Description
Syntax

Verbose mode print out status information.

Logs in to remove system.


telnet hostname

Uncompresses a file, usually with a name ending


in Z.
Unsets a specified variable.
unset variablename

186

Appendix - D

unsetnv

Description

wc

Syntax

usetnv variablename

Description
Syntax

Options

-w

Only print the number of words

Syntax

Options

ami

Description
Syntax

wc options filename

Only print the number of characters.

Description

write

Count the number of words, character and lines in


a text file or files.

-c
-l

who

Unset an environment variable. (Used only in the


C Shell).

Only print the number of lines.

Display the names and other information about


users on the system.
who

Display your user account information.


Send a text message to another user. Use Ctrl-D to
exit.
write username

Appendix E
GLOSSARY

188

absolute
pathname
address

Appendix - E

The complete name of a file, replete with the total path


of directories indicating the files location on the
directory tree. For instance, the absolute pathname
of the file final is /usr/users/kevin/dots/final.
Either the name of a specific machine on a network or
the name of the entire UNIX system. Both meanings
are used in discussions of electronic mail and
communications.

aging

Used by the system to determine when password or


files are old enough to be changed or deleted.

alias

A substitute for a command set up by the user, often


a short substitute for a longer, often-used command.

anonymous ftp

A remote login that requires no password; used for


down loading files from a remote machine. See ftp.

append

To attach text to the end of an existing text file.

application

Software that supplies specific functions to end users:


for exa m ple, wordper fect is a word- pro ces sin g
application.

argument

Used to modify a command on the command line.

ASII[American
standard Code
for Information
Interchange]

A standard format used to communicate data between


different types of computer types. An ASCII file created
on a UNIX computer will be readable on other kinds of
computers.

at

Command that lets you schedule tasks to be run at a


future date.

awk

A programming language geared toward text


manipulation.

BSD[Berkeley
software
Distribution]

A still popular version of UNIX originated at the


University of California-Berkeley that was noted
especially for its advanced networking capabilities.

background

When programs are run in the mode, the user can


perform other tasks and will be notified when the
backg round program is completed. Background
commands are notated with an ampersand [&] at the
end of the command line.

backup

An archived copy of user-specified files, kept as an


insurance policy should the original files be damaged

Appendix - E

189

or corrupted. The UNIX operating system uses the tar


command to create backups.

bangpath

A type of electronic-mail address that relies on a


exclamation point[!] to separate parts of the address.
Derives its name from the UNIX nickname for the
exclamation point, which is bang.

batch

Command that allows you to input many commands


to be run unattached in sequence. The command that
allows batch processing.

batch
processing

Where the system is given a series of commands


[some of which may depend on the output of other
commands] and performs these commands without
any interaction with the user. Although a throwback
to the olden days of computing, much of what can be
done in UNIX can be done with batch processing.

bc

Command that turns a $10,000 workstation into the


equivalent of a $20 calculator.

bin

Directory that contains most of the standard UNIX


programs and utilities.

binary file

A machine- readable format that usually cannot be


read directly by other computers.

bitmap

A method of displaying graphics where the machine


map out every specific point [called pixels] on a
display.

boot

Starting the computer and loading the operating


system into memory.

Bourne shell

A commonly used shell [sh] created by Steven Bourne


of Bell Labs. The original shell.

buffer

A section of random-access memory [RAM] used to


temporarily store data for future use.

bug

Errors in software. Sometimes called unanticipated


features.

A programming language created by Dennis Ritchie


[Bell l labs] in the 1960s. Most UNIX programming
utilizes the C programming language [as well as the
C++ language], since most of UNIX is written in C.

C++

An enhanced version of C written by Barne Stroustrup


[Bell Labs] that is gaining in popularity in both the

190

general computing
programmers.

world

and

Appendix - E

among

UNIX

C shell

A commonly used shell created by Bill joy and others


at University of California-Berkeley.

CPU[Central
processing
Unit]

The grains of the computer; Usually a processor that


performs much of the actual work of the computer,
including processing data and carrying data and
carrying out instructions.

cal

Command that displays a one-month calendar.

cat

Command used to concatenate files, though the most


common usage may be the simple viewing of files.

cd

Command that changes your current directory.

child process

A process started by a parent process through a fork.


Every UNIX process is a child of another process.
Except for init.

Chmod

Command used to change the permissions.

Client

In a distributed file system, a computer that accesses


the files and services on a server. In the X window
system an application that runs on the local machine
[as opposed to the server]

command

An instruction sent to the shell, which interprets the


command and acts upon it.

Command
History
Command line

See history.

Command
mode

In a text editor, the mode where the user supplies


commands for saving and editing files.

Command
substitution

Using the output of one command as input for a new


command.

Comments

Text included in script or programming files that is


not meant to be acted upon by the computer, but
rather used to illuminate commands for someone
reading the file.

Communications
node name

Unique name given to a UNIX system for networking


and communications purposes.

One or more commands, arguments, and options


strung together to create a command.

Appendix - E

191

Compiler

A program that turns source code into programs that


can be executed by the computer. For example, C
source-code files must be run through a compiler
before being run by the computer as a full program.

Compressed
file
Conditional
execution

File that has been shrunk by compression software.

Console

Two meanings. A terminal that is the mother of all


terminals displaying all the system error messages;
or, more generally, the terminal used by the system
administrator.

Core dump

A very bad thing. If an error occurs that a program


cant deal with, the program will display all of the
content of the memory before shutting down; this is
the core dump.

cp

Command used to copy a file from one directory to


another.

cpio

Command used to backup files.

cron

Command used to schedule routine and regular tasks,


such as backing up files.

crontab

The file that contains settings for the cron command.

csh

Command that launches the C shell.

Current
directory

Your current location on the file system. The Cd


command is used to change current directories.

Cursor

A symbol used to display the current position on a


screen. Older terminals use blinking squares ; X
window System Users can use just about anything,
including [our favorite] a Gumby character.

DOS[Disk
operating
System]

An operating system designed for personal computers


by Microsoft and sold under the MS-DOS and PCDOS names.

daemon

Despite the title, a good thing. A daemon [pronounced


demon] is set up to perform a regular, mundane task
without any user initialization or supervision. See
cron for a example of a daemon.

database
management

A structured way of storing information so it can be


easily sorted and otherwise managed by the computer.

A construction where one action wont be taken unless


another action is performed satisfactorily [if this,
then that]

192

Appendix - E

date

Command used to print out or change the current


date and time.

debugger

A program that provides information about bugs in


software.

default

A value or state assumed when no other is supplied.

delimiter

A marker used to distinguish between sections of a


command or a database. With UNIX, spaces are used
as delimiters between portions of a command line.

destination

As you might expect, the target for a directed command.

dev

Directory containing device files.

device

A physical device attached to the computer system,


such as a printer or a modern. UNIXS device drivers
allow the system to talk to these devices.

device file

A file that contains a description of the device so the


operating system can properly send data to and from
the device.

device
independent

Having the ability to perform a task without regard for


a specific computer or peripheral. The text processor
ditroff is device independent because it will work with
many different printers.

directory

A grouping of files and other directories; analogous to


a folder residing in a file cabinet.

display

The physical part of the computer system used to


communicate back and forth with the user.

distributed file
system

A group of two or more physical computers containing


files and programs that appears as one contiguous
system to the end user. Also refers to the software
introduced in System V Release 4 that accomplishes
this goal.

distributed
processing

A theory of computing that allows resources to be


allocated efficiently on a network : for instance, a PC
user could use a more powerful workstation on the
network for computational-heavy processing.

ditroff

A device-independent version of the text processor


troff.

Documenters
Workbench

A group of UNIX programs [troff, etc.] used for various


forms of text processing. Some AT&T licensees treat
troff et.al. as a separate package: other do not.

Appendix - E

193

domain

Best envisioned as a pyramid, a domain is a group


that has control over all group-other domains or nobeneath it.

domain
addressing

Electronic-mail addressing scheme that specifies as


specific address within a large domain; it the address
name is reicbard@mnnet, the domain would be mnnet.

dot command

Just what the name implies; A command preceded by


a dot. Used to tell the shell to execute the commands
in a file; also used by troff and other text-processing
tools to indicate formatting commands.

echo

A UNIX command used to print standard input to


standard output

ed

Retro text editor that edits an ASCII file one line at a


time.

edit buffer

A section of RAM used to contain a file while you edit


the file with a text editor.

editor

A program used to edit ASCII files, such a ed, vi, and


emacs.

editing mode

In a text editor, the mode where editing changes [like


inserting new text, cutting, pasting, etc.occur .Also
known as command mode.

electronic mail

The ability to send and receive mail from different


computer systems.

emacs

Full -screen text editor. Widely distributed, though


not standard on all UNIX implementations.

encryption

A method of encoding a file so that its not readable by


other users, used as a security measure.

end-of-file(EOF)
character

The character, surprisingly enough, that indicates


the end of a file. The combination Ctrl-D is the EOF
character in UNIX.

environment

The sum of all of your shell variables, which are set


individually by you and either stored in your profile
file or set manually by the user as need be.

environment
file

Specific to the Korn shell, this file also contains


environment settings.

environment
variable

An individual shell setting that makes up part of your


environment. For instance, can designate a directory
as your HOME directory as an environment variable.

194

Appendix - E

eqn

D o t c o m m a n d s us e d t o t y p e s e t e q u a t i o n s i n
conjunction with troff.

error message

In a nutshell, a message that tells you something is


awry.

escape key

Character labeled Esc on a keyboard and used for a


variety of functions.

etc

Directory containing everything but device files and


program files.

executable file

A program file that runs simply by typing its name on


the command line.

execute
permission

A setting for an executable file that denotes who can


run the program.

exit

Quitting a running program; in UNIX technically you


are terminating a process.

export

To make environment variables available to other


users.

extension

A suffix to a filename that helps identify the data


contained in the file. A C source-code file usually
ends with a.c suffix.

field

A vertical column of data in a structured data file,


with all the entries of the same type .If we were to
create a file containing the names, phone numbers,
and salary of every employee, with each employees
phone number contained in the second column, we
would call that column a field.

file

A defined set of characters [called bytes] referenced


by its filename.

file sharing

The mechanisms [RFS and NFS] used to make files on


one system available to users on another system.

file system

The pyramid-line method used in UNIX to organize


files and directories. A root directory [analogous to
the top of the pyramid] contains several subdirectories
and these subdirectories in turn may contains further
subdirectories. Any directory can hold files.

filename

The obvious: the name given to a file. Files in the same


directory cannot have the same filename, but files in
different directories may have the same name.

Appendix - E

195

filling

An action in a text processor where as much text as


possible is crammed onto a line.

filter

A type of UNIX program that takes input from one file


and provides output to the display or another file
based on parameters set up by the user.

find

Command used to find a file.

finger

Command that provides information about another


user.

foreground

Commands that have the full attention of the system


and to not return control to the user until the command
is completed. In UNIX, the default is to run commands
in the foreground.

fork

When a program starts another program, called a


child process.

ftp

Command used to connect to any other computer on


your network running ftp. When connected, ftp can
then be used to transfer files to your computer. Can
also be used to access files anywhere on the Internet.

full pathname

The full description of the location of a file on the


directory tree, from the root directory tree, from the
root directory down.

function key

A key [Usually market as F1, F2 etc] that can be


defined by the operating system and/or applications
to perform any number of functions. The actions
attached to the key usually differ from program to
program and operating system to operating system.

gateways

Computers that forward mail, news, or other stuff to


other connected machines.

global

To make changes to all occurrences of a given object;


to change every instance of word to word in a file with
emacs would be an example of a global search and
replace.

graphical user
interface

A metaphoric display of a computer system, with


icons, windows, and scrollbars. Motif, Open Look, the
Macintosh, and Windows are all examples of graphical
use interface.

graphical
windowing
system

See graphical user interface.

196

Appendix - E

grep

A UNIX command that searches for user-specified


string in a file or files.

group

A defined set of users.

head

Command used to display the beginning of a file.

header

The beginning area of a file that contains vital statistics


about the file. A mail file contains a header that
specifies, among other things, the sender of the
message and the route it takes.

header file

A C-language file used to include system-specific


information. Sometimes called include files, as they
are specified in a source-code file with the include
command.

hidden file

A file beginning with a dot [.profile, for example] that


is not returned by the is command unless is told to
return the names of all files in a directory including
hidden files.

hierarchical
file system

See file system.

history

A record of previous commands maintained in your


computers memory. Available only in the C and Korn
shells.

history
substitution

Plucking a command line from a history list and using


it again by typing the number assigned to the
command. Available only in the C and Korn shells.

home directory

The directory the user is placed in after logging in.


This Directory is set in the profile file with the HOME
= command.

hostname

The name of your UNIX system.

icon

A graphical representation of a program or file.

inbox

The storage area for electronic mail that has not been
read.

init

The initial process, which launches when you boot a


computer running the UNIX operating system. All
processes are children of the init process.

inode

The location of information about files in the file


system.

Appendix - E

197

input mode

The mode where a text editor will accept input and


includes it in the edited file. The opposite of editing
mode.

interactive

Inv olves a dialogue of sorts be tween user a nd


computer; the computer does not perform future
tasks until given approval by the user. Most UNIX
work can be done with the opposite of interactive
computing, batch processing.

Internet

The umbrella name for a group of computer networks


that distributes newsgroups and electronic mail
around the world. Computers with access to the
internet are said to be internetworked.

Internet
address

The name given to a computer system that allows it to


receive intemet news and mail.

job

Another name for process or program running.

job control

Changing the status of a job, such as killing it or


resuming a suspected job.

job shell

A superset of the Boume shell [sh] devoted to job


control.

kernel

The core of the UNIX operating system that interacts


directly with the computer.

keyboard

That big thing with keys used to provide input. If you


really looked up the definition of keyboard in a UNIX
tutorial, we strongly advise you to take a remedial
Introduction to Computers class before proceeding
with any UNIX usage.

kill

Command that stop a running process.

kill buffer

A section RAM devoted to storage of deleted text,


which can then be called back into the text editor for
further editing.

Korn shell

The shell [ksh] created by David Korn that improved


on the older, popular Boume shell.

language

Instructions that are translated into commands a


computer can understand. Popular languages include
C, BASIC, PASCAL, and FORTRAN.

library

A set of commonly used C- Language functions.

line editor

A text editor that processes one line at a time, like ed.

198

Appendix - E

link

Instead of wasting disk space on multiple copies of a


commonly used file, one copy of the file is maintained
and other filenames are linked to the original file.

ln

Command used to link files.

local area
network

In the PC world , a group of personal computers


connected via cable to a central computer [the server]
that distributes applications and files. Novell Netware
is an example of a local- area network software
package.

login

Establish a session on the main UNIX system after


providing a login name and a password.

login name

The truncated, unique name given to all users on a


UNIX system.

login shell

A shell launched before the C shell, which allows the


user to login and set environment variables.

logname

See login name

logoff

Quit a UNIX session, typically by typing EXIT, logout,


or Ctrl-D.

lock and feel

The specific arrangement of elements on a screen


[scrollbars, title bars, etc.]
A state where commands are to be executed again and
again until some condition is met.

loop
lp

Command used to print a file.

lpstat

Command used to view the current status of print


requests.

ls

Command that lists the files in a directory.

macros

Short instructions that are expanded by the shell to


mean longer, more explicit commands.

mail

Command used to send and receive mail from other


users.

mailbox

The file area used to store electronic-mail messages.

make

A UNIX program used to create applications based on


system specific information.

man

Command that displays online-manual pages.

man pages

See -online-manual pages.

Appendix - E

199

manual macros

Macros used to create formatted online-manual pages.

memorandum
macros(mm)

Macros used in conjunction with troff to create stylized


business letters, resumes, and reports.

mesg

Command that lets you block messages from other


users created with talk or write

Meta key

A specified key used in conjunction with other keys to


create additional key combinations. On a PC keyboard,
the Alt key is the Meta key; on a sun key- board , the
Alt key is not the Meta key.

more

Command used to display a file one page at a time.

Motif

Created by the open software Foundation, Motif is a


style guide that defines a particular look and feel for
programs. Based on the X Window system.
Make a file system available to users, either locally or
remotely.

mount
multiprocessing

Run more than one task or process at a time, one of


the great strengths of the UNIX operating system.

multitasking

Run more than one task or process at a time; one of


the great strengths of the UNIX operating system,

multiuser

Allow more than one user to be active on the system


at once; one of the great strengths of the UNIX
operating system.

mv

Command that moves a file from one directory to


another.

NFS (Network
File System)

Software developed to create a distributed file system


for use with both UNIX and non UNIX computers.

networking

Connecting computers via phone line or direct link


that they can share data.

newline

Character placed at the end of every line in a text file,


usually created by pressing the Return [or enter] key.

news

Command that displays text files containing news


items.

newsfeed

On the Usenet., all the incoming message files from


the worldwide newsgroups.

news readers

Software dedicated to reading Usenet newsgroups.

newsgroup

On the Usenet, public discussions of various topics.

200

Appendix - E

nice

Command that allows you to assign a lower priority to


a process, thus reveling the stress somewhat on a
overstressed UNIX system.

noclobber

Condition set where a new file cannot overwrite an


existing file with the same line unless the action is
approved by the user.

nroff

Text - processing software, used to output formatting


documents on a line printer.

online-manual
page

Technically detailed information about a command,


accessed by the man command.

Open look

Created by Sun Microsystems and AT&T, open look is


a style guide that defines a particular look and feel for
programs.

operating
system

Software that controls a computer, acts as an interface


for a user, and runs applications. UNIX is an operating
system.

options

Characters that modify the default behaviour of a


command.

ordinary files

A text or data file with no special characteristics; the


most common file type in the UNIX operating system.

orphan

A process that runs even though its parent process


has been killed.

owner

The user with the ability to set permissions for a file.

paging

A memory-management scheme that divides RAM


into 4k segments for more efficient shuffling of data to
and from RAM and a hard disk

parent process

A process that generates another process.

parsing

Logically dividing a command so that we can divine its


meaning.

partition

A section of a hard disk treated as a separate area by


the operating system.

passwd

Command that allows you to change your password.

password

A unique set of characters designed to confirm your


status as a legitimate user of a system.

path

A list of directories the system uses to search for


executable.

Appendix - E

201

pathnames

A description of where a file resides in the file system.


All pathnames flow from the root directory.

permissions

A security tool that determines who can access a file.

pipes

A device that allows standard output from one


command to be used as standard input for another
command.

pg

Command used to view a file one page at a time.

Postscript

A system-independent page-description language


developed by Adobe systems.

process

Essentially, a program running on the computer.

process
identification
number(PID)

A unique number assigned to a program so that it can


be tracked and managed by the operating system and
user.

profile

A description of a users environment variables, stored


in the profile file.

program

A set of instructions for the computer to carryout.

prompt

A Character used by the shell to indicate that it is


waiting for input. In addition, some programs [line
ftp] supply their own unique prompt.

ps

Command that shows what processes are running on


your system.

pwd

Com mand that prints the working, or current,


directory.

RAM(RAndomAccess
Memory)

A physical area of the computer used for short-term


storage of data and programs. When a computer is
turned off, the data in RAM disappears.

RFS (Remote
File System)

Software developed to create a distributed file system


for use only with the UNIX operating system,

read

Command reads in user input and places whatever


the user types into a shell variable.

record

A row in a structured data file. If we were to create a


file containing the names, phone numbers, and salary
of every employee, with each employees information
contained in a single row, we could call that row a
record.

redirection

See standard input and output.

202

Appendix - E

relational
operator

A symbol that sets forth a condition in a programming


language, such as C or awk. These conditions are
based on algebraic notation.

relative
pathname

The location of a file in relation to another location in


the file system.

rlogin

Command that allows you to remotely login another


computer on your network.

rm

Command that deletes a record of the file from the file


system.

root directory

The topmost directory in file system that contains all


other directories and subdirectries . Indicated in all
pathnames as a slash [/].

root user

see superuser,

screen editor

A text editor that allows the user to view a document


one screen at a time and to edit anywhere on that
screen through movement via cursors or mouse.

secondary
prompt

A character used by the shell to indicate that additional


input is needed before a program can run.

sed

Filtering text editor that requires you supply filenames,


operations, and text before running it.

server

In a distributed file system, a computer that supplies


files and services to other computers.

sh

Command used to switch shells.

shell

A program that interprets commands from the user


into instructions the computer can understand.
Popular shells include the Boume, Korn, and C shells.

shell script

A file containing a series of commands for a UNIX


shell.

shutdown

Command used to shutdown a UNIX system before


powering down.

signal

An instruction sent by the operating system to a


program, telling it to shutdown or otherwise modify
its behavior

sort

Command used to sort files.

SPARCstation

Popular UNIX workstation sold by Sun Microsystems.

Appendix - E

203

spell

Command that generates a list of words not contained


in a directory file.

standard error

The default location for error messages, usually your


screen.

standard input
and output

The path that the data takes: Input usually comes


from your keyboard or another program, while output
is usually sent to your screen, to a file, or to a printer
when you specify output to anything but the defaults
you are redirecting the input and output.

state

See system state.

status line

A portion of the screen used to provide feedback to the


user. Not supported by all UNIX programs.

stty

Command that allows you to assign different meaning


to a key.

superuser

The user who can do just about everything possible


within the UNIX operating system.

swapping

Using the hard disk as a slower from of RAM when


theres no RAM available to run programs or to store
data.

symbolic links

An advanced from of a linked file that allows links


between files located on remote file systems.

system
administrator

A worker officially assigned to oversee housekeeping


details on a UNIX system, including adding new users
and scheduling system backups.

system call

Actions available to programs only after


communicating with the kernel, such as printing files
or saving data to disk.

system name

Name used to identify a UNIX system, usually the


version of UNIX used.

system state

The state of the operating system: Single user,


multiuser, administrative, and more.

TCP/IP
(Transmission
Control
Protocol/
Internet
Protocol)

Protocols used to link UNIX and non- UNIX computers


worldwide via phone lines.

tail

Command used to display the final ten lines of a file.

204

Appendix - E

talk

Command that lets you send instant messages to


other users logged on the system.

tar

Command that archives files and data to a backup


device, such as a tape drive or floppy disks.

tbl

Dot commands used to create tables in conjunction


with truff.

telnet

Command that allows you to remotely login another


computer on your network.

terminal

Originally used to describe a dumb machine consisting


of little more than a keyboard and a screen that relies
on the larger system for its computing power. Now
used to describe any computer used to communicate
with a UNIX system.

test

Command used to check variables under the Bourne


shell.

text editor

A UNIX program, like vi or emacs, used to create


ASCII text files

text formatting
program

A program like troff, that takes a text file created


elsewhere and prepares it with formatting command
for output to a printer.

thrashing

A condition where the computer is slowed down


because the system is writing extensively to and from
hard disk when all the RAM is in use.

tmp

Directory used by the system for temporary storage of


working files.

toggle

Turning features on or off in the C and Korn shells.

troff

Text -processing program that processes text files for


output on a typesetting machine. The original troff
was upgraded to support all output devices [typesetting
machines, laser printers, etc] and renamed ditroff,
though most users still refer to ditroff generically as
troff.

UUCP (UNIX to
UNIX System
Copy)

Program that copies files from one system to another


via communication on ordinary telephone lines.

UUCP Network

A series of UNIX computers that pass along electronic


mail and files and around the world.

Appendix - E

205

UNIX

The greatest operating system in the whole wide


world. You should be commanded for your astute and
informed selection of such a great operating system.

Usenet

A loose confederation of computer systems [both


UNIX and non -UNIX] that transmits electronic mail
and newsgroups.

userid

See login name.

utility

A very specialized program that performs only a few


actions.

vi

A very editor that ships with virtually very UNIX


system.

virtual memory

See paging.

wc

Command that returns the number of words in a


given file.

who

Command that displays other users logged on the


system.

wildcards

Special characters within a filename that tells the


shell to search for all files with similar filenames , for
example, would tell the shell to return all files ending
with the character.

window
manager

X window program that defines how other program


actually appear and act on the display.

word processor

Software that combines the powers of text editors and


text processors into single packages.

workstation

Usually a powerful, networked, single- user computer


running the UNIX operating system.

write

Command that lets you send instant messages to


other users logged on the system.

WYSIWYG
(what-you-seeis-what-youget)
X terminal

A term describing word processors and electronic


publishing packages that display exactly how a
document will look before it is printed.

X Window
System

Graphical windowing system created by MIT that can


be described as building blocks for fuller user
interfaces, like motif or open look. It is not tied to any

Computer that runs a local X server, but relies on a


machine elsewhere on the network for most of its
computing power.

206

Appendix - E

p a r t ic ul a r o per a t i n g sy s t e m . B ut i t h a s b e e n
popularized with the UNIX operating system.

XENIX

Older version of
microcomputers.

xterm

Popular X Window program that provides a command


line interface to the UNIX operating system.

zombie

Process that is not active, but not yet killed by the


parent process.

UNIX developed by Microsoft for

You might also like