The book is laced with many diagrams and tables, hundreds of in-chapter tutorials and interactive shell sessions, in--chapter exercises, and end-of chapter problems. A syntax box for every command, tool, and application covered describes the syntax of the command, its purpose, the output produced by the command, and its useful options and features. In addition, every chapter contains a summary of the material covered in the chapter.
THE MMURING SUBJECT
Certainly a measure of the maturity of any technical subject matter is how assimilated and formalized it becomes in the structure of the discipline that gave birth to it. From perhaps an esoteric and theoretical (even idiosyncratic) start, useful scientific knowledge follows a course upward to become a standard, codified, and above all, practical universal discourse. The functional mechanisms that nurture this development have always been an integral part of the scientific community at large.
WHY WE WROTE THIS BOOK
UNIX has reached that level of maturity in the computer science and engineering fields, as witnessed by our writing of this textbook, which we felt was long overdue. Together, we have more than 30 years of practical teaching experience at the college level. Our initial concept for this book grew out of our unwillingness to use either the large, intractable UNIX reference sources or the short, "UNIX-for-Idiots" guides to teach meaningful, complete, and relevant introductory classes on the subject. Moreover, a textbook approach, with pedogogy incorporating in-chapter tutorials and exercises, as well as useful problem sets at the end of each chapter, allows us to present all the important UNIX topics for a classroom 1ecture-laboratory-homework presentation. We can achieve this presentation in a manner that is optimal for learning (i.e., well-thought-out sequencing of topics, well-developed and timely lessons, laboratory work, and homework exercises/problems synchronized with the sequencing of chapters in the book). Additionally because of the depth and breadth of coverage of these topics, anyone interested in furthering their professional knowledge of the subject matter will also find this textbook useful.
THE PURPOSES OF THIS BOOK
Our primary purpose is to describe to readers the UNIX application user's interface (AUI) and to do it in a way that gives the reader insight into the inner workings of the system, along with some important UNIX concepts, data structures, and algorithms. Notable examples are the UNIX file and process concepts and I/O redirection. The secondary purpose of this textbook is to describe some important UNIX software engineering tools for developers of C software and shell scripts. However, we do not describe the UNIX applications programmer's interface (API) in terms of C librarihes and UNIX system calls. In writing this textbook we assumed no previous knowledge of UNIX or programming on the part of the reader.
THE PRESENTAION FORMAT
The book is laced with many diagrams and tables, hundreds of in-chapter tutorials and interactive shell sessions, in--chapter exercises, and end-of chapter problems. A syntax box for every command, tool, and application covered describes the syntax of the command, its purpose, the output produced by the command, and its useful options and features. In addition, every chapter contains a summary of the material covered in the chapter.
PATHWAVS THROUGH THE TEXT
If this book is to be used as the main text for an introductory course in UNIX, all the chapters should be covered, with the possible exception of Chapter 20. If the book is to be used as a companion to the main text in an operating systems concepts and principles course, the coverage of chapters would be dictated by the order in Which the mail topics of the course are covered but should include Chapters 7, 12, and 13. For use in a C or Shell programming course, Chapters 7-20 and relevant sections of Chapters 3--6 would be a great help to students. The extent of coverage of Chapter 20 would depend on the nature of the course--partial coverage in an introductory and full coverage in an advanced course.
THE DESIGN OF FONTS
The following typefaces have been used in the book for various toes of text items. The keyboard presses are enclosed in angle brackets (e.g., <Enter> and <Ctrl-D>).The instruction "press <Ctrl-D>" means to hold the <Ctrl> key down while pressing the <D> key. This instruction is also denoted ^D.
SUPPLEMENTS
A comprehensive and informational Web site containing solutions to the In-Chapter Exercises, source code, and further references and links to other UNIX sites can be found at http://lhotse.up.edu/. Also, you can link to this site from the Addison Wesley Web Site at www awl. com/cseng/titles/0-20l-61260-7.Solutions to the Problems at the end of each chapter are available exclusively to professors using this book to teach a course. For information on obtaining these solutions, please contact your local Addison-Wesley sales representative.
We take full responsibility for any errors in the book. You can send your error reports and comments to us at sarwar@egr.up.edu (or sarwar@up.edu) and bobk@egr.up.edu (or bobk@up.edu). We will incorporate your feedback and fix any errors in subsequent printings.
ACKNOWLEDGEMENTS
We started writing this textbook from scratch during the second week of May 1999 and finished reviewing the final draft with page numbers by the end of the third week of May 2000. Completing such a large project in such a short time is not possib1e without the help of many First and foremost, the authors sincerely thank the editor of the book, Maite Surez-Rivas, for her support, reassurance, professionalism, and understanding throughout this project. She is simply one of the best. We also thank Jason Miranda, Maite's assistant, who did excellent work in getting the proposal and the first draft reviewed in a timely manner, and Lisa Hogue for continuing the fine work after Jason. We also acknowledge the wonderful production crew that diligenily worked so hard with us. Thanks to our developmental editor, Mary Clare McEwing, for valthele feedback, Regina Hagen for desinning a memorable cover and title page, and Jarrod Gibbons for his work on the back cover. Special thanks are extended to Marilyn Lloyd, Project Manager at Pre-Press Company Inc., for her many excellent saseestions and outstanding work in the production phase of this book. The work of the Whole Addison Wesley team gathered by Maite was, in one word, superb! Roses to Maite!
Our sincere thanks to the following reviewers who gave valuable feedback, and numerous accurate and insightful comments. Their contribution has certainly enhanced the quality of the final product.
Ronald E. Bass, Ed.D., Austin Cornxnunity College
Thomas A. Burns, Henry Ford Conunulilty College
Chuck Lesko, Ph.D., Craven Corrirnunity College
Toshimi Minoura, Oregon State University
Selmer Moen, Minot State Unjversity
Gregory B. Newby, University of North Carolirla at Chapel Hill
Dr Marianne Vakalis, Franklin University
Dr. G. Jan Wilms, Union Unjversity Jackson, Tennessee
Thanks go to Kent Thompson, Seruor Systern Administrator, University of Portland School of Engineering Computer Network (UPSECN), for kindly contributing the .Xdefaults file found in Chapter 21. Thanks also go to Dale Frakes, Computer Operator, also of UPSECN, for his continued support in various capacities. He was always there when we needed him.
PERSONAL ACKNOWLEOGMENTS
Syed Mansoor Sarwar First, I wou1d like to thank my dear parents for the unending love, support, inspiration, and encouragement they have given me throughout my life. They are the most wonderful parents, who stnyed awake so I could sleep, took pains so that could be in comfort, and taught me the right values by per sonal exarmples so that I could lead a meed life. I love you Abbujee and Bajee!Thanks also to my brothers and sisters, Masood, Nadeem, Aqeel, Riswana, Nabeel, and Farhana, for their love and friendship. Special thanks go to Nadeem for his contitlued encouragement throughout the project and to Nabeel for reviewing some of the chapters and providing valuable feedback.
This textbook would have never seen the light of day without the continued love, support, and understanding of my partner and cornrnitted helper my wife Robina. Thank you Robina; I couldn't have done it without you. Thanks for taking the kids to the soccer and basketball games when it was my turn, keeping them busy when I had to work on the book, and tolerating the priner noise in the middle of the night! And, thank you my little bundles of joy, my son Hassaan and daughter Maham, for the love and happiness that you have given me. Thanks also for allowing me to work for long hours. I love you both. Last, but not least, thanks to my coauthors, Robert Koretsky and Aqeel Sarwar, for their reassurance throughout the project. Bob, this book would have been difficult to complete without your continued help. Robert M. Koretsky I thank my Wife Kathe, daughter Tara, and son Cody, for all of the love and support they have given me over the years. I also thank Mansoor Sarwar, for his inspiration and friendship. Apeel Sarwar I give thanks to my parents for their personal sacrifices and hard work in raising me and teaching me the right values. Thanks also go to my elder brothr, Syed Mansoor Sarwar, for supporting me and giving me educational direction when I had none. I thank my entire family, parents, brothers, and sisters, for giving me true love. Last, but not least, I thank my wife for her support and my son for making my day, every day.
Chapter 1 Overview of Operating Systems
l.l Introduction
l.2 What Is an Operating System
l.3 Operating System Services
l.4 Character Versus Graphical User Interfaces
l.5 Types of Operating Systems
l.6 The UNIX Family
Summary
Problems
Chapter 2 Brief History of the UNIX Operating System
2.1 Introduction
2.2 Historical Development of the UNIX Operating System
2.2.l Beginnings
2.2.2 Research Operating System
2.2.3 AT&T System V
2.2.4 Berkely Software Distributions
2.2.5 The History of Shells
2.2.6 Current and Future Developments--LINUX
2.3 Variations in UNIX Systems
Summary
Problems
Chapter 3 Getting Started
3.l Introduction
3.2 Computer System Hardware
3.2.1 Main/Primary storage
3.2.2 Central Processing Unit (CPU)
3.2.3 Disk
3.2.4 Bus
3.2.5 I/O Devices
3.3 UNIX Software Architecture
3.3.l Device Driver Layer
3.3.2 The UNIX Kernel
3.3.3 The System Call Interface
3.3.4 Language Libraries
3.3.5 UNIX Shell
3.3.6 Applications
3.4 Logging On and Logging Off
3.5 Correcting Mistakes
3.6 Some Important System Setups
3.7 Some Useful Commands for the Beginner
3.7.l Changing Your Password
3.7.2 Getting Help
3.7.3 Finding Out Who You Are and What the Name of Your UNIX System Is
Summary
Problems
Chapter 4 UNIX Shells
4.1 Introduction
4.2 Various UNIX Shells
4.2.1 Shell Programs
4.2.2 Which Shell Suits Your Needs
4.2.3 Ways to Change Your Shell
4.2.4 Shell Start-up Files and Environment Variables
4.3 Some Other Useful General-Purpose Commands
4.3.1 Creating and Displaying Directories
4.3.2 Displaying Files
4.3.3 Printing Files
4.3.4 Displaying a Calendar
4.3.5 One-Way Real-Time Messaging
4.3.6 Notification of and Permission for Electronic Communication
4.3.7 Creating Pseudonyms for Commands
4.3.8 Displaying System Up Time
4.4 Shell Metacharacters
Summary
Problems
Chapter 5 Editing Text Files
5.l Introduction
5.2 How to Do Short and Simple Edits by using the pico Editor
5.2.l Creating the Text of an e-mail Message with the pico Text Editor
5.2.2 How to Start, Save a File, and Exit
5.2.3 General Keystroke Commands and Cursor Management
5.2.4 Cutting/Pasting and Searching
5.3 Obtaining More Control by Using the vi Editor
5.3.l Shell Script File
5.3.2 How to Start, Save a File, and Exit
5.3.3 The Format of a vi Command and the Modes of Operation
5.3.4 Cursor Movement and Editing Commands
5.3.5 Yank and Put (Copy and Paste) and Substitute (Search and Replace)
5.3.6 Setting the vi Environment
5.3.7 Executing Shell Commands from Within vi
5.4 Getting the Maximum Control by Using the emacs Editor
5.4.l DOS Aliases
5.4.2 How to Start, Save a File, and Exit
5.4.3 Cursor Movement and Editing Commands
5.4.4 Keyboard Macros
5.4.5 Cut or Copy and Paste and Search and Replace
5.5 Optional--How to Do Graphical Editing by Using emacs and the X Window System
5.5.1 Editing Data Files
5.5.2 How to Start, Save a File, and Exit
5.5.3 X Window emacs Menus
Summary
Problems
Chapter 6 Electronic Mail
6.l Introduction
6.2 How to Use the UNIX mail Command Effectively
6.2.l Sending and Reading e-mail with the UNIX mail Command
6.2.2 Sending e-mail with mail
6.2.3 Reading e-mail with mai1
6.2.4 Saving Messages in Folders
6.2.5 Replying to and Forwarding Messages--and Including Attachments
6.2.6 mail Aliases
6.3 elm--A Full Screen Display e-mail System
6.3.l Sending a Message in elm
6.3.2 Sending e-mail with elm
6.3.3 Reading e-mail in elm
6.3.4 Forwarding and Replying to an e-mail Message in elm
6.3.5 Saving Messages in Folders
6.3.6 elm Aliases
6.4 pine--Another Full-Screen Display e-mail System
6.4.l Sending an e-mail Message by Using pine with an Attachment Created in vi
6.4.2 Sending e-mail with pine
6.4.3 Reading e-mail with pine
6.4.4 Disposing of e-mail in Folders in pine
6.4.5 Using the pine Address Book
6.4.6 A Summary of pine Commands
Summary
Problems
Chapter 7 Files and File System Structure
7.l Introduction
7.2 The UNIX File Concept
7.3 Types of Files
7.3.l Simple/Ordinary File
7.3.2 Directory
7.3.3 Link File
7.3.4 Special File (Device)
7.3.5 Named Pipe (FIFO)
7.4 File System Structure
7.4.1 File System Organization
7.4.2 Home and Present Working Directories
7.4.3 Pathnames: Absolute and Relative
7.4.4 Some Standard Directories and Files
7.5 Navigating the File Structure
7.5.1 Determining the Absolute Pathname for Your Home Directory
7.5.2 Browsing the File System
7.5.3 Creating Files
7.5.4 Creating and Removing Directories
7.5.5 Determing File Attributes
7.5.6 Determing the Type of a File's Contents
7.6 File Representation and Storage in UNIX
7.7 Standard Files and File Descriptions
7.8 End of File (eof) Marker
Summary
Problems
Chapter 8 File Security
8.l Introduction
8.2 Password-Based Protection
8.3 Encryption-Based Protection
8.4 Protection Based on Access Permission
8.4.1 Types of Uses
8.4.2 Types of File Operations/Access Permissions
8.5 Determining and Changing File Access Privileges
8.5.1 Determing File Access Privileges
8.5.2 Changing File Access Privileges
8.5.3 Default File Access Privileges
8.6 Special Acces Bits
8.6.l The Set-User-ID (SUID) Bit
8.6.2 The Set-Group-ID (SGID) Bit
8.6.3 The Sticky Bit
Summary
Problems
Chapter 9 Basic File Processing
9.l Introduction
9.2 Viewing Contents of Text Files
9.2.1 Viewing Complete Files
9.2.2 Viewing Files One Page at a Time
9.2.3 Viewing the Head or Tail of a File
9.3 Copying, Moving, and Removing Files
9.3.l Copying Files
9.3.2 Moving Files
9.3.3 Removing/Deleting Files
9.3.4 Determing File Size
9.4 Appending to Files
9.5 Combining Files
9.6 Comparing Files
9.7 Removing Repeated Lines
9.8 Printing Files and Controlling Print Jobs
9.8.1 UNIX Mechanism for Printing Files
9.8.2 Printing Files
9.8.3 Finding the Status of Your Print Requests
9.8.4 Canceling Your Print Jobs
Summary
Problems
Chapter l0 Advanced File Processing
10.l Introduction
l0.2 Regular Expressions
l0.3 Compressing Files
l0.4 Sorting Files
l0.5 Searching for Commands and Files
l0.6 Searching Files
10.7 Cutting and Pasting
l0.8 Encoding and Decoding
l0.9 The Encryption and Decryption
Summary
Problems
Chapter 11 File Sharing
ll.l Introduction
ll.2 Duplicate Shared Files
ll.3 Common Login for Memebers of a Team
ll.4 Setting Appropriate Access Permissions on Shared Files
ll.5 Common Group for Members of a Team
ll.6 File Sharing Via Links
ll.6.l Hard Links
ll.6.2 Drawbacks of Hard Links
11.6.3 Soft/Symbolic Links
ll.6.4 Pros and Cons of Symbolic Links
Summary
Problems
Chapter 12 Redirection and Piping
12.l Introduction
l2.2 Standard Files
12.3 Input Redirection
l2.4 Output Redirection
l2.5 Combining Input and Output Redirection
l2.6 I/O Redirection with File Descriptors
l2.7 Redirection Standard Error
12.8 Redirecting stdout and stderr in One Command
l2.9 Redirecting stdin, stdout, and stderr in One Command
l2.10 Redirecting Without Overwriting File Contents (Appending)
12.1l UNIX Pipes
l2.l2 Redirection and Piping Combined
l2.l3 Error Redirection in the C Shell
l2.l4 Recap of I/O and Error Redirection
Summary
Problems
Chapter 13 Processes
l3.1 Introduction
l3.2 Running Multiple Processes Simultaneously
l3.3 UNIX Process States
l3.4 Execution of Shell Commands
l3.5 Process Attributes
13.6 Process and Job Control
l3.6.l Foreground and Background Processes and Related Commands
l3.6.2 UNIX Daemons
13.6.3 Sequential and Parallel Execution of Commands
l3.6.4 Abnormal Termination of Commands and Processes
l3.7 Process Hierarchy in UNIX
Summary
Problems
Chapter 14 Networking and Internetworking
l4.l Introduction
l4.2 Computer Networks and Internetworks
l4.3 The Reasons for Computer Networks and Internetworks
l4.4 Network Models
l4.5 The TCP/IP Protocol Suite
14.5.l TCP and UDP
l4.5.2 Routing of Application Data--The Internet Protocol (IP)
l4.5.3 IPv4 Addresses in Dotted Decimal Notation
l4.5.4 Symbolic Names
l4.5.5 Translating Names to IP Addresses--The Domain Name System
l4.6 Internet Services and Protocols
14.7 The Client-Server Software Model
14.8 Application Software
14.8.l Displaying the Host Name
14.8.2 Displaying List of Users Using Hosts on a Network
l4.8.3 Displaying the Status of Hosts on a Network
l4.8.4 Testing a Network Connection
l4.8.5 Displaying Information about Users
l4.8.6 Remote Login
l4.8.7 Remote Command Execution
l4.8.8 File Transfer
l4.8.9 Remote Copy
l4.8.l0 Interactive Chat
l4.8.ll Tracing the Route from One Site to Another Site
Summary
Prob1ems
Chapter 15 Introductory Bourne Shell Programming
15.1 Introduction
l5.2 Running a Bourne Shell Script
l5.3 Shell Variables and Related Commands
l5.3.1 Reading and Writing Shell Variables
l5.3.2 Command Substitution
15.3.3 Exporting Environment
l5.3.4 Resetting Variables
15.3.5 Creating Read-Only User-Defined Variables
15.3.6 Reading from Standard Input
l5.4 Passing Arguments to Shell Scripts
15.5 Comments and Program Headers
15.6 Program Control Flow Commands
l5.6.l The if-then-elif-else-fi Statement
15.6.2 The for Statement
l5.6.3 The while Statement
l5.6.4 The until Statement
l5.6.5 The break and continue Commands
l5.6.6 The case Statement
Summary
Problems
Chapter 16 Advanced Bourne Shell Programming
l6.1 Introduction
l6.2 Numeric Data Processing
l6.3 The Here Document
l6.4 Interrupt (Signal) Processing
l6.5 The exec Command and File I/O
l6.5.1 Execution of a Command Without Creating a New Process
l6.5.2 File I/O via the exec Command
l6.6 Functions in the Bourne Shell
l6.6.1 The Reasons for Functions
l6.6.2 Function Definition
16.6.3 Function Invocation/Call
16.6.4 Examples of Functions
16.7 Debugging Shell Programs
Summary
Programs
Chapter 17 Introductory C Shell Programming
l7.l Introduction
l7.2 Running a C Shell Script
17.3 Shell Variables and Related Commands
17.3.1 Reading and Writing Shell Variables
17.3.2 Command Substitution
17.3.3 Exporting Environment
17.3.4 Resetting Variables
17.3.5 Reading from Standard Input
17.4 Passing Arguments to Shell Scripts
l7.5 Comments and Program Headers
17.6 Program Control Flow Commands
17.6.l The if the-e1se-endif Statement
l7.6.2 The foreach Statement
l7.6.3 The while Statement
l7.6.4 The break, continue, and goto Commands
l7.6.5 The switch Statement
Summary
Problems
Chapter 18 Advanced C Shell Programming
18.l Introduction
l8.2 Numeric Data Processing
l8.3 Array Processing
18.4 The Here Document
18.5 Interrupt (Signal) Processing
l8.6 Debugging Shell Programs
summary
Problems
Chapter 19 File System Backup
l9.1 Introduction
l9.2 Archiving and Restoring Files Via tar
l9.2.l Archiving Files
19.2.2 Restoring Archived Files
l9.2.3 Copying Directory Hierarchies
19.3 Software Distributions in the tar Format
Summary
Problems
Chapter 20 Unix Tools for Software Development
20.l Introduction
20.2 Computer Programming Languages
20.3 The Compilation Process
20.4 The Software Engineering Life Cycle
20.5 Program Generation Tools
20.5.l Generating C Source Files
20.5.2 Indenting C Source Code
20.5.3 Compiling C Programs
20.5.4 Handling Module-Based C Software
20.5.5 Building Object Files into a Library
20.5.6 Working with Libraries
20.5.7 Version Control
20.6 Stattic Analysis Tools
20.6.l Verifying Code for Portability
20.6.2 Source Code Metrics
20.7 Dynamic Analysis Tools
20.7.1 Tracing Program Execution
20.7.2 Source Code Debugging
20.7.3 Run-Time Performance
Summary
Problems
Chapter 21 X Window System --The UNIX Graphical User Interface
21.l Introduction
21.2 User-Computer Interactivity and the X Window System
2l.2.l The Key Components of Interactivity--Events and Request
21.3 The Role of a Window Manager in the User Interface and fvwm
21.3.l Functions and Appearance of the Window Manager Interface
2l.3.2 The Appearance and Operation of fvwm
2l.4 Customizing the X Window System and fvwm
2l.4.l Command Line Changes to an X Window System Application
21.4.2 Preference Changes in .Xdefaults and .xinitrc Initialization Files
2l.4.3 Typical Changes in .fvwmrc to Customize the fvwm Window Manager
Summary
Problems
Appendix: Command Dictionary
Glossary
Index