Table Of ContentecaferP
When choosing between two evils, I always like to try the one
I've never tried before.
.Mae West
An operating system si like an old friend. You may be in daily contact with
him or only see him occasionally. Over the years a firm bond of friendship
develops. You come to realize that he si not perfect, and still you feel com-
fortable with his idiosyncrasies. In short, you accept him for who he .si
OpenVMS, the traditional operating system used by many Digital
Equipment Corporation (DEC) VAX and Alpha processors, si an old friend
to many of us. However, you will likely need to learn a version of the UNIX
operating system, for UNIX si the operating system of choice for most pro-
cessors that use innovative hardware architectures. You may be attracted by
the stability that UNIX provides sa a development medium in a rapidly
changing hardware market. After all, UNIX si the closest we have come to a
generic operating system, suited to controlling a variety of hardwares from
many vendors. Whatever your reasons for learning UNIX, if you are already
familiar with OpenVMS, this may well be the book for you.
The book si intended to help you mold the interactive computing skills
that you learned using OpenVMS into the skills necessary for computing
in the UNIX framework. It si not meant to be a UNIX user's manual, nor
si it designed to teach UNIX from first principles. The book draws upon
the experience of observing professionals with varying degrees of Open-
VMS expertise grapple with the concrete and philosophical issues of
UNIX. This book emphasizes UNIX derived from Berkeley UNIX, or
Berkeley Software Distribution (BSD), although many of the features dis-
cussed are pertinent to any version of UNIX. Both the C shell and the
Korn shell, two of the most widely used command-line interfaces to
Preface xiii
indicates how they differ from those of OpenVMS. uoY will learn how to
tailor the environment to get the most from each UNIX terminal session.
Chapter 3 concludes with two topics that OpenVMS users making the tran-
sition to UNIX find the most irksome: the recall and cumbersome editing of
command lines and the use of online help and the UNIX document set.
At this point, you should be yearning for some serious interactive com-
puting. Chapter 4 introduces a subset of file-management commands that
you are likely to need in the first few terminal sessions. oS sa not to bewil-
der the beginner, we leave the more complex file-management commands
for Chapter 8. In Chapter 4, you should begin to comprehend the power of
the UNIX environment.
Chapter 5 follows with a comparison of the most commonly used UNIX
and OpenVMS line and screen editors in preparation for some meaningful
application development. Chapter 5 also introduces two utilities available to
OpenVMS users sa part of the POSIX environment that offer powerful fea-
tures for pattern matching and subsequent file modification.
At this stage, you should be ready to communicate with fellow users and
systems staff. Chapter 6 covers the basic features of interactive communica-
tions and batch communications via e-mail. For the reader who must com-
municate with users on remote computers, Chapter 31 revisits e-mail sa
part of a discussion of processor-to-processor communications.
Chapter 7 introduces the UNIX equivalents of queuing batch and print
requests and making tape-drive requests. There are no surprises for the
OpenVMS user when it comes to printing files in UNIX, but the same can-
not be said of magnetic tape and batch processing. The use of magnetic
tapes in UNIX si in some ways arcane, but the real surprise si UNIX's
inability to handle batch processing. Chapter 7 explains that this si not a
shortcoming, but a difference in philosophy. UNIX has no need for batch
queues, since you can easily manage multiple tasks interactively.
By the time you get to Chapter 8, you will need more complex file-man-
agement commands. Chapter 8 builds upon the introductory discussion of
file management in Chapter 4 by introducing new commands and options.
Chapter 9 discusses programming using a high-level language in the
UNIX environment and provides insight into the programming tools for
which UNIX si renowned, some of which are available sa layered products
under OpenVMS. Chapter 9 discusses tools for debugging, profiling, and
maintaining large programs with examples from the C and FORTRAN
languages.
I Preface
Preface xv
has been made to draw attention to and describe the similarities and differ-
ences between UNIX and OpenVMS that are most important to applica-
tion users and developers. Any learning process is facilitated by drawing
upon previous experience, and learning UNIX should be no exception.
Conventions
Throughout this book the following conventions are used"
noitnevnoC gninaeM
Form The general form of a command.
Example Particular example of a command defined by form.
A command to the OpenVMS command-language interpreter.
Commands are shown in uppercase.
A command to the UNIX Korn shell program. Although the
default prompt si the same sa that for OpenVMS, we have labeled
examples with the operating system for you to easily distinguish
the two. Commands are shown in lowercase, unless the shell pro-
gram specifically requires uppercase.
A command to the UNIX C shell program. Commands are shown
in lowercase, unless the shell program requires specifically uppercase.
Italios Emphasizes important terminology or features.
Code A UNIX or OpenVMS command or file.
What follows to the end of the line si a comment (UNIX only).
What follows to the end of the line si a comment (OpenVMS
only).
[argument] Optional argument.
<CR> A carriage return in OpenVMS and UNIX. Assumed for lla com-
mands and shown in this book only when a special meaning si
implied.
<CTRL> The control key on the terminal.
<ESC> The escape key F( 11 on many terminals).
OpenVMS The term OpenVMS si used to refer to the OpenVMS operating
system, both on XAV and Alpha processors, unless otherwise
noted.
I Preface
xvi ecaferP
Unlike OpenVMS, UNIX interprets uppercase and lowercase characters
differently.
SMVnepO XINU
ShOw UsErS % WHO
OpenVMS Interactive Users WHO : Command not found
22-Feb-1997 11:25:34.53
% who
Total number of interactive
system tty01 Feb 22 i0:39
users : 1 UsernameProcess Name
PID Terminal SYSTEM
SYSTEM 0000001AE TXA0:
The ohw command, found sa /bin/who, provides information on each
interactive user, including the login name, the terminal in use, and the time
he or she logged in to the system.
Preface to the Third Edition
When we developed the second edition of this book, we both worked for
Digital Equipment Corporation (DEC), the company that brought Open-
VMS to the computing world. Four years later, DEC si long gone, having
been bought by Compaq Computer Corporation (Compaq), which in turn
was acquired by Hewlett-Packard.
Regardless of the company brand on the product, OpenVMS continues
to live on with thousands of users throughout the world. Many of those
OpenVMS users need to know how to do their daily tasks on UNIX or
Linux systems, and that's why we revised this book again.
For this third edition, our goal has been to update the existing material.
When we talk about the various flavors of UNIX, we also consider Linux.
In addition, we've provided some new information about shell program-
ming, Perl, and using the Emacs editor.
We will disappoint many who find their favorite command missing.
There si simply no way to keep up with the wonderful explosion of free and
open source software that clusters around UNIX. Whether it's part of one
of the GNU Linux distributions or available from a Web site such sa
SourceForge, software written just for fun and just for the utility it can pro-
vide to others has kept the spirit and substance of the old DECUS tapes.
Whatever else the future brings, the need to mix-and-match operating
systems, and the need for competence across them, will remain.
Preface xvii
Acknowledgments for the Third Edition
Our thanks to
Our contact at Digital Press/Butterworth-Heinemann, Pam Chester;
Bill Costa of the Computing and Information Services Department of the
University of New Hampshire, who provided su with thorough corme-v iew
ments, and also provided su with access to sih own excellent Web site of
UNIX and OpenVMS migration; Additional thanks to Tim for sih exten-
evis help with Perl and lla of Chapter ;01
llA the Linux advocates, enthusiasts, and evangelists who worked for DEC
and Compaq (you know who you ;)!era
Special thanks to ngh, the true guru;
And of course, our families.
Richard Holstein and Joseph McMullen
April 2003
Chapter Plates
The chapter plates were drawn by Maria Ruotolo, adapted from some of
the great masters:
.1 Adapted from "The Thinker" by Auguste Rodin (1840-1917).
.2 Adapted from "The Creation of Man" by Michelangelo Buonar-
roti (1475-1519).
.3 Adapted from "The Lovers" by Pablo Picasso (1881-1973).
4. Adapted from "Jeune Femme Devant el Lit" by Amedeo
Modigliani (1884-1920).
.5 Adapted from "Three Women at the Spring" by Pablo Picasso
(1881-1973).
.6 Adapted from an Egyptian tomb painting~l 8th-Dynasty Egyp-
tian mural.
.7 Adapted from "The Suitor's Visit" by Gerard ter Borch (1677-
1687).
.8 Adapted from "Portrait of Dr. Gachet" by Vincent van Gogh
(1853-1890).
I Preface
iiiv<> Preface
Adapted from A" Portrait of Sultan Selin II" yb Ralis Haydar
,
(1570-1638).
.01 Adapted from "Gare "erazaL-tniaS yb Edouard Monet (1832-
.)3881
.11 Adapted from "The Anatomy Lecture of .rD Nicolaes Tulp" yb
Harmenszoon naV Rijn Rembrandt (1606-1669).
.21 Adapted from tnasaeP" Woman Digging" yb Vincent nav Gogh
(1853-1890).
.31 Adapted from "The Last Supper" yb Leonardo ad Vinci (1475-
.)4651
I
Introduction
History si yhposolihp teaching yb .selpmaxe
---Dionysius of sussanracilaH
This book provides an introduction to the UNIX operating system. Most
introductory UNIX texts assume no prior knowledge of interactive com-
puting. Here, you must have a working knowledge of the OpenVMS oper-
ating system from Hewlett-Packard (HP), because this text si designed to
help you make a smooth transition from OpenVMS to UNIX. This book
started sa a user's guide for a group of scientists who saw an increasing need
for OpenVMS users to compute on processors running the UNIX operat-
ing system. Recognizing that mixed operating system environments like
ours were becoming more common, we decided to expand the user's guide
into the more comprehensive text presented here.
This book was developed originally in response to the increase in UNIX
usage compared to OpenVMS. This book does not, however, attempt to
convince the OpenVMS user that UNIX si a preferable operating system:
We do not regard UNIX sa a better operating system than OpenVMS, nor
OpenVMS as superior to UNIX. Each has strengths and weaknesses, which
we note when relevant to the comparative teaching process that the text
employs throughout.
The text si intended to do more than describe how to perform a given
OpenVMS command or function in UNIX. Certainly such descriptions are
useful and may represent all that the occasional UNIX user requires. How-
ever, for those who intend to develop complex applications, we have tried
to show some of the features that make UNIX a powerful development
medium.
4 I. I Evolution
Unlike OpenVMS, UNIX si not a single product, but rather the evolu-
tion of an original idea and design philosophy into a number of different
products, each of which has unique features. It si not possible to describe lla
these features, nor would it serve any purpose other than to confuse the
reader. We shall concentrate on the more generic features. That said, we will
look at how some versions of UNIX originated and what the original design
philosophies behind them mean to today's OpenVMS user making the
transition to UNIX.
I.I Evolution
Much has been written on the subject of UNIX's evolution and the current
trends toward standardization. This section gives only a synopsis and com-
pares UNIX's evolution to the corresponding development of OpenVMS.
Ken Thompson first conceived of UNIX in 1969 at the American Tele-
phone and Telegraph Company's (AT&T) Research Division at Bell Labo-
ratories in Murray Hill, New Jersey, to allow him to run a program on a
PDP-7 computer. The program, Space Travel, originally ran on a General
Electric GE645 computer, which used an operating system called Multics.
Multics was developed at the Massachusetts Institute of Technology (MIT)
and was one of the first timesharing operating systems. The first version of
UNIX, which was written in assembly language, incorporated many fea-
tures of Multics.
The decision to rewrite UNIX in a higher-level language and, thus, to
make it portable between computer systems, came in 1972, when Thomp-
son rewrote the UNIX software in a language called .B Dennis Ritchie, also
of Bell Laboratories, extensively modified B in 1973, renaming it C.
Whether fortuitous or not, the decision to make UNIX portable si the
main reason for the popularity of UNIX today. UNIX provides a stable
development medium for a rapidly changing hardware market. Applica-
tions can often be ported directly to hardware of different types without
costly redevelopment.
In 1974, the decision to license the UNIX source code to universities
established a second major evolutionary pathway, the Berkeley Software
Distribution (BSD). BSD Version 3.0, released in 1979, included many
enhancements to the original Bell Laboratories version of UNIX, some of
which we discuss in subsequent chapters. Notable were several portable lan-
guage compilers that expanded the transparent operating system function-
ality on different types of hardware to include transparent program
development tools. The development of BSD illustrates one aspect of the