Statistics
16
Views
0
Downloads
0
Donations
Uploader

高宏飞

Shared on 2025-12-21
Support
Share

AuthorJerry Peek, Grace Todino-Gonguet, John Strang

If you're new to Unix, this concise book will tell you just what you need to get started and no more. This fifth edition is the most effective introduction to Unix in print, covering Internet usage for email, file transfers, and web browsing. It's an ideal primer for Mac and PC users who need to know a little about Unix on the systems they visit. The new edition also contains many major and minor updates to help the reader navigate Unix's ever-expanding capabilities. In response to the popularity of Linux, the book now focuses on the popular bash shell preferred by most Linux users. A new chapter explains how to use ftp, pine for mail, and offers useful knowledge on how to surf the web. And the author has included tips throughout the text on security basics, especially in the Internet and networking sections. The book includes a completely updated quick reference card to make it easier for the reader to access the key functions of the command line.

Tags
No tags
ISBN: 0596002610
Publisher: O'Reilly Media
Publish Year: 2002
Language: 英文
Pages: 173
File Format: PDF
File Size: 1.5 MB
Support Statistics
¥.00 · 0times
Text Preview (First 20 pages)
Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

Learning the Unix Operating System ,Title.27339 Page 1 Friday, January 4, 2002 4:48 PM
,Title.27339 Page 2 Friday, January 4, 2002 4:48 PM
Learning the Unix Operating System Fifth Edition Jerry Peek, Grace Todino, and John Strang Beijing • Cambridge • Farnham • Köln • Paris • Sebastopol • Taipei • Tokyo ,Title.27339 Page 3 Friday, January 4, 2002 4:48 PM
Learning the Unix Operating System, Fifth Edition by Jerry Peek, Grace Todino, and John Strang Copyright © 2002, 1998, 1993, 1987, 1986 O’Reilly & Associates, Inc. All rights reserved. Printed in the United States of America. Published by O’Reilly & Associates, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472. Editor: Laurie Petrycki Production Editor: Mary Brady Cover Designer: Edie Freedman Printing History: 1986: First Edition. Written by Grace Todino and John Strang. 1987: Second Edition. Revisions by Tim O’Reilly. April 1989: Minor corrections. August 1993: Third Edition. Additions and revisions by Jerry Peek. June 1994: Minor corrections. January 1998: Fourth Edition. Additions and revisions by Jerry Peek. January 2002: Fifth Edition. Additions and revisions by Jerry Peek. Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of O’Reilly & Associates, Inc. The association of the image of a horned owl and the topic of learning Unix is a trademark of O’Reilly & Associates, Inc. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and O’Reilly & Associates, Inc. was aware of a trademark claim, the designations have been printed in caps or initial caps. While every precaution has been taken in the preparation of this book, the publisher assumes no responsibility for errors or omissions, or for damages resulting from the use of the information contained herein. ISBN: 0-596-00261-0 [M] [11/01] ,Copyright.27216 Page iv Friday, January 4, 2002 4:48 PM
About the Author Jerry Peek has used Unix since the early 1980s. He has consulted on Unix and VMS, developed and taught Unix courses, been a staff writer for O’Reilly & Associates, Inc., and worked as a programmer and system administrator. Grace Todino (Gonguet) is now a “professional expatriate,” having lived in Oman, Gabon, and Holland for the last 10 years. She currently resides in Sarawak (Malaysia) with her geophysicist husband, Christophe, and their children, Gabriel, Raphael, and Lucie. Grace was one of the original authors of the Nutshell Handbooks Managing UUCP and Usenet and Using UUCP and Usenet. She now writes and edits travel arti- cles for local publications. John Strang is an Assistant Professor of Diagnostic Radiology at the University of Rochester, Rochester, NY. His research interests are in CAT scan and MRI of the body, as well as in computerization of radiologic images. He received his education at MIT (BS and MS), Northwestern Medical School (MD), and UCLA and Stanford (post-graduate medical training). Colophon Our look is the result of reader comments, our own experimentation, and feedback from distribution channels. Distinctive covers complement our distinctive approach to technical topics, breathing personality and life into potentially dry subjects. The animal on the cover of Learning the Unix Operating System is a horned owl. The horned owl is the most powerful of North American owls, measuring from 18 to 25 inches long. This nocturnal bird of prey feeds exclusively on animals—primarily rab- bits, rodents, and birds, including other owls. It locates these animals by sound rather than sight, since its night vision is little better than ours. To aid its hunting, an owl has very soft feathers that muffle the sound of its motion, making it virtually silent in flight. A tree-dwelling bird, it generally chooses to inhabit the old nests of other large birds such as hawks and crows, rather than build its own nest. Mary Brady was the production editor and copyeditor for Learning the Unix Operat- ing System . Linley Dolby and Claire Cloutier provided quality control. Joe Wizda wrote the index. Edie Freedman designed the cover of this book, based on her own series design.The cover image is a 19th-century engraving from the Dover Pictorial Archive. Emma Colby produced the cover layout with QuarkXPress 4.1, using Adobe’s ITC Gara- mond font. David Futato designed the interior layout based on a series design by Nancy Priest. The print version of this book was created by translating the DocBook XML markup of its source files into a set of gtroff macros using a filter developed at O'Reilly & Associates by Norman Walsh. Steve Talbott designed and wrote the underlying macro set on the basis of the GNU troff –gs macros; Lenny Muellner adapted them to XML and implemented the book design. The GNU groff text formatter Version 1.11.1 was used to generate PostScript output. The text and heading fonts are ITC ,Colophon.27089 Page 1 Friday, January 4, 2002 4:47 PM
Garamond Light and Garamond Book. The illustrations that appear in the book were produced by Robert Romano and Jessamyn Read using Macromedia FreeHand 9 and Adobe Photoshop 6. Whenever possible, our books use a durable and flexible lay-flat binding. ,Colophon.27089 Page 2 Friday, January 4, 2002 4:47 PM
Ta ble of Contents Preface ...................................................................................................... vii 1. Getting Star ted ................................................................................ 1 Working in the Unix Environment ....................................................... 1 Syntax of Unix Command Lines ........................................................ 11 Types of Commands ........................................................................... 14 The Unresponsive Ter minal ............................................................... 14 2. Using Window Systems ............................................................. 17 Intr oduction to Windowing ................................................................ 18 Starting X ............................................................................................. 19 Running Programs .............................................................................. 21 Working with a Mouse ....................................................................... 26 Working with Windows ...................................................................... 29 Other Window Manager Features ...................................................... 35 Unr esponsive Windows ..................................................................... 37 Other X Window Programs ................................................................ 39 Quitting ............................................................................................... 40 3. Using Your Unix Account ........................................................ 42 The Unix Filesystem ........................................................................... 42 Looking Inside Files with less ............................................................ 54 Pr otecting and Sharing Files .............................................................. 56 Graphical Filesystem Browsers .......................................................... 61 v 7 January 2002 13:15
vi Table of Contents Completing File and Directory Names .............................................. 62 Changing Your Password ................................................................... 62 Customizing Your Account ................................................................ 63 4. File Management ......................................................................... 66 File and Directory Names .................................................................. 66 File and Directory Wildcards ............................................................. 67 Cr eating and Editing Files .................................................................. 69 Managing Your Files ........................................................................... 74 Printing Files ....................................................................................... 81 5. Redirecting I/O ............................................................................. 87 Standard Input and Standard Output ................................................ 87 Pipes and Filters ................................................................................. 92 6. Using the Internet and Other Networks ............................. 97 Remote Logins .................................................................................... 97 Windows from Other Computers .................................................... 100 Lynx, a Text-based Web Browser .................................................... 101 Transferring Files .............................................................................. 104 Electr onic Mail .................................................................................. 108 Usenet News ..................................................................................... 118 Interactive Chat ................................................................................. 123 7. Multitasking ............................................................................... 130 Running a Command in the Background ....................................... 131 Checking on a Process ..................................................................... 132 Cancelling a Process ......................................................................... 134 8. Where to Go from Here .......................................................... 136 Documentation ................................................................................. 136 Shell Aliases and Functions ............................................................. 139 Pr ogramming .................................................................................... 139 Using Unix on Non-Unix Systems ................................................... 140 Glossar y ................................................................................................ 143 Index ...................................................................................................... 149 7 January 2002 13:15
Preface The Unix Family of Operating Systems An operating system (or “OS”) is a set of programs that controls a com- puter. It contr ols both har dware (things you can touch, like keyboards, scr eens, and disk drives) and softwar e (application programs that you run, like a word processor). Some computers have a single-user OS, which means that only one per- son can use the computer at a time. Many older OSes (such as MS-DOS) can also do only one job at a time. But almost any computer can do a lot mor e if it has a multiuser, multitasking operating system such as Unix. These powerful OSes let many people use the computer at the same time and let each user run several jobs at once. Unix was invented more than 30 years ago for scientific and professional users who wanted a very powerful and flexible OS. It’s been significantly developed since then. Because Unix was designed for experts, it can be a bit overwhelming at first. But after you get the basics (from this book!) you’ll start to appreciate some of the reasons to use Unix: • It comes with a huge number of powerful application programs. You can get many others for free on the Internet. (The GNU utilities, available from the Free Software Foundation, are very popular.) You can thus do much more at a much lower cost. • Not only are the applications often free, but some Unix versions are also free. Linux is a good example. Like the free applications, most fr ee Unix versions are of excellent quality. They’r e maintained by vii 7 January 2002 13:09
viii Preface volunteer programmers who want a powerful OS and are frustrated by the slow, bug-ridden OS development at some big software com- panies. • Unlike OSes such as Microsoft Windows and MacOS that are designed for certain types of hardware, Unix runs on almost any kind, from tiny embedded systems to giant supercomputers. After you read this book, you’ll be ready to use many kinds of computers without learn- ing a new OS for each one. • In general, Unix (especially without a windowing system) is less resource-intensive than other major operating systems. For instance, Linux will run happily on an old system with a x386 micropr ocessor and let multiple users share the same computer. (Don’t bother trying to use the latest versions of Microsoft Windows on a system that’s mor e than a few years old!) If you need a windowing system, Unix lets you choose from modern featur e-rich inter faces as well as from simple ones that need much less system power. Anyone with limited resources — educational institutions, organizations in developing coun- tries, and so on—can use Unix to do more with less. • Much of the Internet’s development was done on Unix systems. Many Inter net web sites and Internet service providers use Unix because it’s so flexible and inexpensive. With powerful hardware, Unix really shines. Versions of Unix Ther e ar e several versions of Unix. Until a few years ago, there wer e two main versions: the line of Unix releases that started at AT&T (the latest is System V Release 4), and another from the University of California at Berkeley (the last version was 4.4BSD). Some past and present commer- cial versions include SunOS, Solaris, SCO Unix, AIX, HP/UX, and ULTRIX. Fr eely available versions include Linux, NetBSD, and FreeBSD (FreeBSD is based on 4.4BSD-Lite). Many Unix versions, including System V Release 4, merge earlier AT&T releases with BSD features. The POSIX standard for Unix-like operating systems defines a single interface to Unix. Although advanced features dif- fer among systems, you should be able to use this introductory handbook on any system. When we write “Unix” in this book, we mean “Unix and its versions” unless we specifically mention a particular version. 7 January 2002 13:09
Interfaces to Unix Unix can be used as it originally was, on typewriter-like terminals, from a shell prompt on a command line. (See the section “Examples,” later in this chapter.) Most versions of Unix also work with window systems (some- times called Graphical User Interfaces, or GUIs). These allow each user to have a single screen with multiple windows—including “terminal” win- dows that act like the original Unix interface. (Chapter 2 explains window system basics.) Although a window system lets you use Unix without typing text at a shell pr ompt, we’ll spend most of our time on that traditional command-line inter face to Unix. Why? • Every Unix system has a command-line interface. If you know how to use the command line, you’ll always be able to use the system. • If you become a more-advanced Unix user, you’ll find that the com- mand line is actually much more flexible than a windowing interface. Unix programs are designed to use together from the command line — as “building blocks”—in an almost infinite number of combina- tions, to do an infinite number of tasks. No windowing system that we’ve seen (yet!) has this tremendous power. • You can launch and close windowing programs from the command line, but windowing programs generally can’t affect a command line or programs you run from one. • Once you learn to use the command line, you can use those same techniques to write scripts. These little (or big!) programs automate jobs you’d have to do manually and repetitively with a window sys- tem (unless you understand how to program a window system, which is usually a much harder job). See the section “Programming” in Chapter 8 for a brief introduction to scripting. • In general, text-based interfaces are much easier than GUIs for sight- and hearing-impaired users. We aren’t saying that the command-line interface is right for every situa- tion. For instance, using the Web — with its graphics and links—is usually easier with a GUI web browser. But the command line is the fundamental way to use Unix. Understanding it will let you work on any Unix system, with or without windows. Preface ix 7 January 2002 13:09
x Preface What This Handbook Covers This book teaches basic system utility commands to get you started with Unix. Instead of overwhelming you with lots of details, we want you to be comfortable in the Unix environment as soon as possible. So we cover a command’s most useful features instead of describing all its options in detail. We also assume that your computer works properly; someone has started it, knows the procedur e for turning the power off, and knows how to per- for m system maintenance. In other words, we don’t cover Unix system administration. Unix users can choose between many differ ent user interfaces — shells and window systems. Our examples show the bash shell and the GNOME and KDE window environments. We’ve chosen them because they’re popular and make good examples, not because we think they’re always “the best.” If you do advanced work or set up Unix systems for other users, we rec- ommend learning about a variety of shells and window systems and choosing the best ones for your needs. The principles explained in this book should help you use any Unix configuration. What’s New in the Fifth Edition Unix keeps evolving, and this book changes with it. Although most tips in this book work on all Unix systems, old and new, there have been changes since 1997 that justify a fifth edition. Over the years, readers have asked us to include topics that couldn’t be covered in just a few para- graphs — a text editor, for instance. We’ve decided to let this little book gr ow just a bit by adding several-page overviews of popular Unix tools: the Pico text editor, the Pine email program, the Lynx web browser, and two interactive chat programs. Networking is much more common, so we’ve added a new chapter about it. Our windowing examples show newer window systems and you’ll find sections about command-line edit- ing. There’s a new Glossary with definitions of common terms, and the Index has also been expanded. Finally, we’ve made changes suggested by our readers. 7 January 2002 13:09
Format The following sections describe conventions used in this handbook. Commands We intr oduce each main concept first, and then break it into task-oriented sections. Each section shows the best command to use for a task, explains what it does, and shows the syntax (how to put the command line together). The syntax is given like this: rm filename Commands appear in boldface type (in this example, rm). You should type the command exactly as it appears in the example. The variable parts (her e, filename) will appear in italic type; you must supply your own value. To enter this command, you would type rm followed by a space and the name of the file that you want to remove, then press the RETURN key. (Your keyboard may have a key labeled ENTER or an arr ow with a right-angle shaft instead of a RETURN key.) Thr oughout this book, the term enter means to type a command and press RETURN to run it. Examples Examples show what should happen as you enter a command. Some examples assume that you’ve created certain files. If you haven’t, you may not get the results shown. We use typewriter-style characters for examples. Items you type to try the example are boldface. System messages and responses are normal text. Her e’s an example: $ date Tue Oct 9 13:39:24 MST 2001 $ The character “$” is the shell (system) prompt. To do this example, you would type date and then press RETURN . The date command responds “Tue Oct 9 13:39:24 MST 2001” and then retur ns you to the prompt. Preface xi 7 January 2002 13:09
xii Preface Text you see in examples may not be exactly what you see on your scr een. Dif ferent Unix versions have commands with differ ent outputs. Sometimes we edit screen samples to eliminate distracting text or make them fit the page. Problem Checklist We’ve included a problem checklist in some sections. You may skip these parts and go back to them if you have a problem. Exer cises Some sections have exercises to reinforce text you’ve read. Follow the exercises, but don’t be afraid to experiment on your own. Exercises have two columns. The lefthand column tells you what to do and the righthand column tells you how to do it. For example, a line in the section “Exercise: entering a few commands,” near the end of Chapter 1, shows the following: Get today’s date Enter date To follow the exercise, type in the word date on your keyboard and then pr ess the RETURN key. The lefthand column tells you what will happen. After you try the commands, you’ll have a better idea of the ones you want to learn mor e about. You can then get more infor mation fr om a source in the section “Documentation,” in Chapter 8. Comments and Questions Please address comments and questions concerning this book to the pub- lisher: O’Reilly & Associates, Inc. 1005 Gravenstein Highway North Sebastopol, CA 95472 (800) 998-9938 (in the United States or Canada) (707) 829-0515 (international or local) (707) 829-0104 (fax) 7 January 2002 13:09
To ask technical questions or comment on the book, send email to: bookquestions@or eilly.com We have a web site for the book where examples, errata, and any plans for future editions are listed. You can access this site at: http://www.or eilly.com/catalog/lunix5/ For more infor mation about books, conferences, Resource Centers, and the O’Reilly Network, see the O’Reilly web site at: http://www.or eilly.com If you write to us, please include information about your Unix environ- ment and the computer you use. You’ll have our thanks, along with thanks from future readers of this handbook. Acknowledgments H. Milton Peek reviewed the first draft of this edition. Jeff Kawski acted as the technical editor. Chris Stone of O’Reilly & Associates, Inc. gave infor- mation about Mac OS X and reviewed the section about it. And Tim, thanks from Jerry for all your advice and support during my 12 years of writing for O’Reilly. Preface xiii 7 January 2002 13:09
7 January 2002 13:09
1 Getting Started In this chapter: • Working in the Unix Environment • Syntax of Unix Command Lines • Types of Commands • The Unresponsive Terminal Befor e you can use Unix, a system staff person has to set up a Unix account for you. The account is identified by your user name, which is usually a single word or an abbreviation. Think of this account as your of fice—it’s your place in the Unix environment. Other users may also be at work on the same system. At many sites, there will be a whole network of Unix computers. So in addition to knowing your username, you may also need to know the hostname (name) of the computer that has your account. Alternatively, your account may be shared between all computers on the local network, and you may be able to log into any of them. Once you’ve logged in to your account, you’ll interact with your system by typing commands at a command line, to a program called a shell. You’ll get acquainted with the shell, enter a few commands, and see how to handle common problems. To finish your Unix session, you’ll log out. Working in the Unix Environment Each user communicates with the computer from a terminal. To get into the Unix environment, you first connect to the Unix computer. (Your ter- minal is probably already connected to a computer.* But Unix systems also let you log into other computers across a network. In this case, log into your local computer first, then use a remote login command to con- nect to the remote computer. See the section “Remote Logins” in Chapter 6.) * Some terminals can connect to many computers through a kind of switchboard called a port contender or data switch. On these terminals, start by telling the port contender which computer you want to connect to. 1 7 January 2002 13:10
2 Chapter 1: Getting Started After connecting your terminal, if needed, you start a session by logging in to your Unix account. To log in, you need your username and a passwor d. Logging in does two things: it identifies which user is in a session, and it tells the computer that you’re ready to start work. When you’ve finished, log out—and, if necessary, disconnect from the Unix computer. ˆM If someone else has your username and password, they pr obably can log into your account and do anything you can. They can read private information, corrupt or delete important files, send email messages as if they came from you, and more. If your computer is connected to a net- work — the Inter net or a local network inside your organi- zation — intruders may also be able to log in without sitting at your keyboard! See the section “Remote Logins” in Chap- ter 6 for one explanation of one way this can be done. Anyone may be able to get your username — it’s usually part of your email address, for instance. Your password is what keeps others from logging in as you. Don’t leave your password anywhere around your computer. Don’t give your password to anyone who asks you for it unless you’re sur e they’ll preserve your account security. Also don’t send your password by email; it can be stored, unprotected, on other systems and on backup tapes, where other people may find it and then break into your account. If you suspect that someone is using your account, ask sys- tem staff for advice. If you can’t do that, setting a new pass- word may help; see the section “Changing Your Password” in Chapter 3. Unix systems are case sensitive. Most usernames, commands, and file- names use lowercase letters (though good passwords use a mixture of lower- and uppercase letters). Before you log in, be sure your CAPS LOCK key is off. Connecting to the Unix Computer If you see a message from the computer that looks something like this: login: you’r e pr obably connected! You can skip ahead to the section “Logging in Nongraphically” and log in. 7 January 2002 13:10
Otherwise, if someone nearby uses the same kind of computer system you do, the easiest way to find out if you’re connected is probably to ask for help. (We can’t cover every user’s situation exactly. There are just too many possibilities.) If there’s no one to ask, look ahead at the section “Logging in Nongraphi- cally,” later in this chapter, as well as the section “Starting X” in Chapter 2 and the section “Remote Logins” in Chapter 6. You may recognize your situation. If that doesn’t help, but your computer seems to be running an operating system other than Unix (such as Microsoft Windows), check your menus and icons for one with the name of the Unix computer you’re supposed to connect to. You might also find a program named either telnet, eXceed, ssh, VMware, procomm, qmodem, kermit, or minicom, or something relat- ing to remote access. Logg ing in Nongraphically The process of making yourself known to the computer system and get- ting to your Unix account is called logging in. If you’ve connected to the Unix host from another operating system, you may have been logged into Unix automatically; in this case, you should be able to run Unix programs, as shown later in this chapter in the section “Shells in a Window System” and the section “The Shell Prompt.” Otherwise, before you can start work, you must connect your terminal or terminal window to the computer you need (as in the previous section) and identify yourself to the Unix system. Ther e ar e generally two ways to log in: graphically and nongraphically. If your screen has a window or windows floating in it, something like Figure 2-2A, you probably need to log in graphically, as explained by “the sec- tion “A. Ready to Run X (with a Graphical Login)” in Chapter 2. Otherwise, to log in nongraphically, enter your username (usually your name or initials) and your private password. The password does not appear as you enter it. When you have logged in successfully, you’ll get some system messages and finally the shell prompt (where you can enter Unix commands). A successful login to the system named nutshell could look like Example 1-1. Working in the Unix Environment 3 7 January 2002 13:10
4 Chapter 1: Getting Started Example 1-1. Nongraphical login nutshell login: john Password: Last login: Mon Oct 8 14:34:51 EST 2001 from joe_pc Sun Microsystems Inc. SunOS 5.7 Generic October 1998 ------------- NOTICE TO ALL USERS ----------------- The hosts nutshell, mongo, and cruncher will be down for maintenance from 6 to 9 PM tonight. --------------------------------------------------- My opinions may have changed, but not the fact that I am right. Tue Oct 9 12:24:48 MST 2001 $ In this example, the system messages include a maintenance notice, a “fortune,” and the date. Although this example doesn’t show it, you may be asked for your ter minal type, accounting or chargeback information, and so on. The last line to appear is the Unix shell prompt. When you reach this point, you’re logged in to your account and can use Unix com- mands. Instead of a shell prompt, you may get a menu of choices (“email,” “news,” and so on). If one choice is something like “shell prompt” or “command prompt,” select it. Then you’ll be able to follow descriptions and examples in this book. The messages you see at login time differ from system to system and day to day. Shell prompts can also differ. Examples in this book use the cur- rency sign $ as a prompt. Let’s summarize logging in nongraphically, step by step: 1. If needed, connect your terminal or terminal window to the Unix sys- tem. 2. Get a “login:” prompt. 3. Type in your username in lower case letters at the prompt. For exam- ple, if your login name is “john,” type: login: john Pr ess the RETURN key. The system should prompt you to enter your password. If passwords ar en’t used on your system, you can skip the next step. 7 January 2002 13:10
The above is a preview of the first 20 pages. Register to read the complete e-book.