Practical Linux 2000 Ebook free download pdf pdf

  

  28

  V

  21

  22

  23

  24

  25

  26

  27

  29

  19

  30

  31

  VI A

  B

  C

  D

  M. Drew Streib Michael Turner John Ray Bill Ball, et al.

  A Division of Macmillan USA 201 West 103rd Street Indianapolis, Indiana 46290

  20

  18

  I

  8

  1

  2

  3

  4

  5

  II

  6

  7

  9

  17

  10

  11

  III

  12

  13

  14

  15

  IV

  16

  Contents at a Glance Linux PRACTICAL

  Acquisitions Editor Practical Linux Gretchen Ganser

  Copyright © 2000 by Que Corporation Development Editor Hugh Vandivier All rights reserved. No part of this book shall be reproduced, stored in

  Technical Editor a retrieval system, or transmitted by any means, electronic, mechanical, Kurt Wall photocopying, recording, or otherwise, without written permission

  Managing Editor from the publisher. No patent liability is assumed with respect to the Matt Purcell use of the information contained herein. Although every precaution has

been taken in the preparation of this book, the publisher and author Project Editor

  Pamela Woolf assume no responsibility for errors or omissions. Nor is any liability assumed for damages resulting from the use of the information con-

  Copy Editor tained herein.

  Michael Dietsch Indexers

  International Standard Book Number: 0-7897-2251-8 Eric Schroeder

Library of Congress Catalog Card Number: 99-068220 Kevin Kent

  Proofreader Printed in the United States of America

  Benjamin Berg First Printing: June, 2000 Team Coordinator

  Cindy Teeters

  02 01 00 4 3 2 1

  Interior Designer Anne Jones

  Cover Designer Trademarks Rader Design All terms mentioned in this book that are known to be trademarks or

  Copywriter service marks have been appropriately capitalized. Que cannot attest to Eric Borgert the accuracy of this information. Use of a term in this book should not

  Layout Technicians be regarded as affecting the validity of any trademark or service mark.

  Tim Osborn Mark Walchle Warning and Disclaimer

  Every effort has been made to make this book as complete and as accu- rate as possible, but no warranty or fitness is implied. The information provided is on an as is basis. The authors and the publisher shall have neither liability nor responsibility to any person or entity with respect to any loss or damages arising from the information contained in this book. ii

  Saving Keystrokes with Shell History 21 Using the Tab Key to Complete Commands 21 Entering Multiple Commands 22 Breaking Long Command Lines 22 Entering Commands in GNOME 23 Entering Commands in KDE 23

  Introduction 1

  2 Entering Commands 19

  Getting Help 14 Getting Help with the man Command 14 Getting Help in X11 with the xman Client 15 Getting Help with the info Command 15 Getting Help with the GNOME Help Browser 16 Getting Help Using the KDE Help Browser 17 Getting Help with the whatis Command 17 Getting Help with the apropos Command 18

  Logging Out of Linux 13 Rebooting Linux 13 Shutting Down Linux 13

  Creating a User Account at the Command Line 9 Creating a User Account in X11 with the usercfg Command 9 Changing Your Password 11 Running Commands as the Root Operator 11 Using Virtual Consoles 12

  Welcome to Linux 6 What Is a Shell? 7 Logging in to Linux 8

  1 Introducing the Shell 5

  I Linux Basics

  Contents

  Creating Shell Commands 24 Using the >, >>, and < Redirection Operators 24 Redirecting Error Output by the Numbers 26 Using Pipes to Build Commands 26 Running Programs in the Background 27 Creating Shell Commands with autoexpect 28

  Viewing Text Files 39 Viewing Text Files with the cat Command 40 Viewing Text Files with the less and more Pager Commands 41

  Listing Directories and Files with the ls Command 38 Echoing Directory Contents with the echo Command 39

  Printing the Current Working Directory 36 Changing Directories with the cd Command 36 Listing Directories 37

  3 Navigating the Linux File System 35

  Selecting a Shell 32 Changing Shells with the chsh Command 33

  Using Wildcards 31 Building Regular Expressions 31

  Controlling Programs 29 Using Job Control 29 Using the ps and kill Commands 30

  Entering Commands at the Shell Command Line 20 Case Sensitivity 20 Editing the Command Line 20

  iv PRACTICAL Linux Creating Files and Directories 43

  Using touch to Create and Update Files and Directories 43 Creating Directories with the mkdir Command 43

  Copying Files and Directories 44 Copying Files with the cp Command 44 Copying Directories with the cp Command 44

  Moving and Renaming Files and Directories 45 Moving and Renaming Files and Directories with the mv Command 45

  Creating Symbolic Links 46 Linking Files with the ln Command 46 Linking Directories with the ln Command 48

  Deleting Files and Directories 49 Deleting Files with the rm Command 49 Deleting Directories with the rmdir Command 49 Deleting Directories with the rm Command 50

  Finding Files and Directories 50 Finding Files with the find Command 50 Finding Files and Directories with the locate Command 51 Finding Programs and Manual Pages with the whereis Command and the which Command 52

  Using the GNOME gmc Client 52 Creating Directories Using the GNOME gmc Client 53 Copying, Moving, and Renaming Files and Directories Using the GNOME gmc Client 54 Creating Symbolic Links Using the GNOME gmc Client 54 Deleting Files and Directories using the GNOME gmc Client 54 Searching for Files with GNOME’s Search Tool 55

  Using the KDE File Manager kfm 55 Creating Directories Using KDE’s kfm 56 Copying Files and Directories Using kfm 56 Moving and Renaming Files and Directories and Creating Symlinks Using kfm 57 Deleting Files and Using KDE’s Trash Can 57 Searching the File System with KDE’s kfind Client 57

  Searching Text Files 58 Using the grep Command 58 Using the egrep Command 60 Using the fgrep Command 60 Using the strings Command 61 Using the egrep and fgrep Commands 61

4 Using Text Editors 63

  Selecting an Editor 64 Commercial Linux Word Processors 64 Using Screen Editors 67 Using Stream Editors 75

  Using Linux Dictionaries 77 Getting the web2 Dictionary 77 Dictionaries: Rolling Your Own 78 Spell Checking with the ispell Command 78 Using Internet Dictionaries with the dict Clients 79

  Saving Paper with the mpage Command 79 Creating Formatted Documents 80 Using Text-Formatting Filter Commands 80 Using Text-Processing Systems 82

  CONTENTS

  7 Working with Hard Drives 113

  Enabling PCMCIA Services 138 Determining Your PCMCIA Controller 139

  9 Enabling a PC Card Device 137

  Adding a Zip Drive 132 Before Installing a Zip Drive 133 Ejecting, Password-Protecting, and Read- Write–Protecting Zip Disks 134

  Adding a Tape Drive 130 Installing a Tape Drive 130 Using the mt Command 131

  8 Adding Tape and Zip Drives 129

  Partitioning a Hard Drive with the fdisk Command 120 Manipulating Partitions with the sfdisk Command 123 Mounting a Hard Drive or Other Device 124 Mounting and Unmounting Remote NFS Hard Drives 126 Mounting File Systems with linuxconf 126

  Choosing a File System 118 Adding a Hard Drive 119 Identifying Hard Drives and Devices 119

  Determining the Volume Device and Partition 114 Hard Drive Devices 115

  Creating Aliases 108 Using the linuxconf Utility 109

  5 Printing Files 87

  Customizing Your Login 105 Customizing Your Command-Line Prompt 106

  Displaying Environment Variables with the printenv Command 100 Displaying Environment Variables with the env Command 102 Setting an Environment Variable on the Command Line 102 Deleting an Environment Variable from the Command Line 103 Setting Command PATHs 104

  6 Configuring Your Environment 99

  II Configuring Your System

  Reordering Print Jobs 95 Stopping Print Jobs 95 Sending Faxes with the lpr Command 95

  Printing Files at the Command Line 93 Listing the Print Queue 93 Controlling Printers and Print Jobs 93

  Configuring Printers for WordPerfect for Linux 91 Spooling Files to Your Printer 92

  Adding Printers 88 Checking Your Printer 88 Adding a Local Printer by Editing /etc/printcap 90

  Using the cardmgr Command 141 Listing Your PC Card and Drivers 141 Disabling cardmgr Command Event Notification 142 Linux PRACTICAL

  Using the cardctl Command 142 Checking the Status of Incoming or Outgoing Obtaining the Status of PC Cards 143 Faxes 164

  Listing Your PC Card Configuration 143 Viewing Received Faxes 164 Inserting a PC Card 144 Printing a Received Fax 165 Ejecting a PC Card 144 Deleting a Received Fax 165 Suspending and Restoring PC Card Power 145

  III

  The X Window System

  10 Adding a Pointing Device 147

  12 Running and Configuring X 169

  Adding a Mouse 148 Configuring XFree86 with XF86Setup 170 Using and Configuring gpm 148 Configuring a Synaptics Touchpad 149

  Configuring Xfree86 with

  XConfigurator 170 Installing a Joystick 151 Configuring Your Graphics Card 170 Configuring a Joystick 152

  Starting X11 171

11 Configuring a Modem and Fax Service 153

  Using the startx Command 171 Using Virtual Consoles with X 172 Selecting a Modem for Linux 154

  Starting Multiple X Sessions 172 Using the dmesg Command to Check Serial Port Status 154

  Stopping X 173 Testing Your Modem with the echo Command 155 System and X Session Control with Display

  Managers 173 Creating the /dev/modem Device 156 Logging In with xdm 173 Creating /dev/modem with the ln Customizing the xdm Banner Screens 176 Command 156

  Customizing the .xinitrc Startup Script 178 Getting Serial Port Information with the set- serial Command 156

  Customizing Your Workspace 179 Enabling Dial-In Service 157 Setting a Screen Saver 179 Configuring Linux for Dial-in Service 157 Setting the Background Desktop Color 182

  Configuring Linux for Dial-in PPP Setting the Background Desktop Service 160 Pattern 182 Using a Desktop Wallpaper 182

  Configuring Fax Service 161 Setting the Mouse Pointer 184 Configuring the fax Shell Script 162 Configuring the Mouse 185 Testing Your Fax Configuration 163 Configuring Terminal Windows 186 Sending a Fax Using the fax Shell

  Using X11 Resources 187 Script 164 Setting Up to Wait for Incoming Faxes 164 vi

  CONTENTS Using the xloadimage Client to View

  13 Using a Window Manager 189

  Captures 210 Window Managers and Desktop

  Capturing and Viewing Screens with the xv Environments 190

  Client 210 Using the xmag Client to Capture Magnified Selecting an X11 Window Manager 190

  Images 212 The K Desktop Environment and kwm 191 Enlightenment 192

  15 Using Graphics and Multimedia Tools 215

  Window Maker 193 Selecting a Graphics Program 216 Starting a Window Manager 193

  Using the GIMP Client 216 Starting KDE 194 Using ImageMagick 224 Starting Enlightenment/GNOME 194

  Starting Window Maker 195 Translating or Converting Graphics 229

  Using the pbm, ppm, and pnm Utilities 233

  14 Performing Common X Operations 197

  Previewing Graphics and PostScript Using X11 Toolkit Command-Line Documents 234 Options 198

  Using the gv PostScript Previewer 234 Using Geometry Settings to Set Window Using Adobe Acrobat 237 Size 198

  Playing Music CDs 240 Setting Foreground and Background Colors 199

  Watching and Listening to Internet TV and Radio 243 Moving, Resizing, and Managing Windows 200

  Using RealPlayer 244 Specifying an X11 Window Title 200 Playing Animations and Movies with the

  Minimizing, Maximizing, or Closing xanim Client 245

  Windows 201 Viewing X11 Fonts 202

  IV Connecting to Your Internet Service Viewing X11 Fonts with the xfontsel

  Provider

  Client 203 Using the xfd Client to View Font

16 Connecting to Your Internet Service

  Character Maps 203

  Provider 249

  Copying and Pasting Text 206 Configuring a PPP Connection 250 Using the xcutsel Client to Copy Text 206 Checking Your Serial Port and Modem 251 Copying Text with the xclipboard Client 207 Checking Your Linux Kernel and File System for PPP Support 251

  Capturing Windows and the Desktop 208 Using xwd to Capture Windows 208

  Configuring PPP for Your ISP 253 Using xwud to Display Window Dumps 209 Linux PRACTICAL

  Configuring Your PPP Connection Using the ncftp Command 292 Scripts 254

  Downloading with the ncftp Command 292 Editing the ppp-on Connection Script 254 Using Netscape to Download Files 293 Configuring PPP with kppp 255

  19 Using Web Browsers 295

  Starting a PPP Connection 257 Configuring the Lynx Browser 298 Starting a PPP Connection Using the minicom

  Program 257 Using Netscape Communicator 300

  Starting a PPP Connection with the ppp-on Downloading and Installing Netscape Script 258 Communicator 300 Starting a PPP Connection with kppp 258 Working with Netscape Communicator 303 Closing Your PPP Connection 258

  20 Using telnet and Internet Relay Chat 309

  Checking Your PPP Connection 259 Checking PPP Connections with the ifconfig

  Using the telnet Command 310 Command 259 Connecting to Other Computers 310 Getting PPP Statistics with the pppstats Downloading Files During telnet Command 260 Sessions 313 Getting PPP Statistics with kpppload 260

  Chatting with Internet Relay Chat 314 Testing PPP Connection Speed with the ping Starting an irc Session 314 Command 260 Getting PPP Interface Information with the route Command 261

  V System Administration Troubleshooting PPP Connections with Your System Log 261

  21 Basic Shell Programming 321

  17 Using Electronic Mail 265

  What Shell Scripts Are Used For 322 Retrieving Electronic Mail 266 Writing Shell Programs 323

  Using fetchmail 266 Good Programming Practice 323 A Sample Program 323

  Selecting a Mail Program 269 Using mail 269

  Using Shell Variables 327 Using pine 271 Using Variables in Scripts 328 Using Netscape Messenger to Create, Send, A Sample Script 328 and Read Mail 274

  Using Shell Constructs 332 Managing Electronic Mail 280 Conditional Constructs: The if Configuring procmail to Filter Mail 281 Statement 333 Repeating Commands with while 336

18 Using FTP 283

  Repeating Commands with for 336 Using ftp to Download Files 286 Writing Shell Functions 336

  Using ftp Help Commands 291 A Simple Shell Function 337 Using a Library 338 viii

  CONTENTS Using the usercfg Tool 363

  22 Using Basic Programming Tools 339

  Adding a User with usercfg 365 Recompiling Code 340

  View/Edit Users 367 Locking a User 368 Compiling Programs with gcc 340

  Unlocking a User 369 Linking Programs with the ld Linker 341 Removing a User 370

  Adding a Group 371 Building Programs with the make

  Editing an Existing Group 373 Command 342

  Removing a Group 373 A Sample Program 343 Finishing Up with usercfg 373 make Options 344

  Adding, Editing, and Deleting Users Using A Sample Program: the make the Command Line 373

  Command 345 Adding Users with useradd 374 A Sample Program 345 Modifying Users with the usermod

  Specifying Different Makefiles 347 Command 374 Deleting Users with the userdel

  Getting Started Quickly with New Command 375

  Programs 347 Adding, Editing, and Deleting Groups 376 Specifying Different Makefiles 349

  Adding Groups with the groupadd Building X11 Makefiles with the xmkmf

  Command 376 Script 349

  Modifying Groups with the groupmod Command 376

  23 Using Boot Managers 351

  Deleting Groups with the groupdel Command 376 How Linux Boots: LILO/LOADLIN 352 Changing User and Group Ownership 377 Configuring LILO 352

  Managing Groups with gpasswd 377 Changing the Default Boot 354 Using the chgrp Command 378 Passing Kernel Parameters 354

  Booting to a Specific Run Level 355 Changing File Ownership and Permissions 378 Using LOADLIN 356

  Using the chown Command 378 Booting from DOS to Linux 356 Using the chmod Command 379 Setting Up LOADLIN 357

  Advanced Concepts: Password Authentication Passing Kernel Parameters with

  Module 382 LOADLIN 359 Improving System Security Using PAM 382

  24 Managing Users and Groups 361

  25 Managing Scheduling Services 389

  Users, Groups, and Their Relation to the System 362 Configuring inittab and rc Files 390 The inittab File 391 The rc Files 394

  Linux PRACTICAL

  Configuring crontab Scheduling Enabling the Network File System Service 395 Service 425

  Enabling crontab Service 396 Enabling Dial-In Service 427 crontab Entries 396 Setting Up the PPP Options Files 427 Allowing and Preventing Access to the crontab Configuring Getty Devices 428 Service 399

  Configuring the at Command Service 400

27 Managing Daemons 431

  Enabling at Command Service 400 Editing and Creating Run Levels 434

  Common Problems with the at Command 401 Editing inittab 435

  Allowing and Preventing Access to the at Command Service 403 Using chkconfig 436 Listing Services by Using chkconfig 436

26 Managing Network Connections 405

  Removing a Service by Using chkconfig 437 Adding a Service by Using chkconfig 437 Configuring Network Connections

  Resetting Service Information 437 Manually 406

  Configuring the Loopback Interface 406 Editing Startup and Shutdown Scripts 438

  Configuring an Ethernet Card 407 A Sample init Script 438 Setting a Default Route 408 init Script Checklist 440 Configuring Hostname and DNS

  Customizing the Login Greeting 441 Information 409 Customizing the Login Greeting for Network Using DHCP to Configure Your Network Connections 442 Settings 411

  Enabling and Customizing the MOTD 443 Configuring Network Connections with linuxconf 411 Using the tksysv Tool 443

  Using the Network Configuration Tool 412 Adding a Service with tksysv 444 Setting the Hostname and the Domain Using ksysv 446 Name 413 Starting and Stopping Network Setting the Name Servers 413 Services 447 Adding a PPP Interface 413 Adding a SLIP Interface 416

  Using the ntsysv Tool 448 Adding a PLIP Interface 418 Enabling FTP Access 448 Adding an Ethernet Interface 420 Enabling a Web Server 450

  Setting Up a Router 421 Configuring the Apache Web Server 451 Connecting Two Linux Systems 423 Connecting a Mac OS Machine to a Linux System 423 Connecting a Windows Machine to a Linux System 424 x

  CONTENTS

  Performing System Backups 504 Compressing and Decompressing Files and Directories 504 Compressed Archiving with the tar Command 505 Using find to Locate Files for tar Backups 509 Using taper for Backups 513 Backing Up with Floppy Disks 517 Backing Up with Removable Drives 518

  Installing Modules 535 Listing Loaded Modules 535 Creating Module Dependencies 536 Enabling Modules at Boot Time 537

  Configuring Your Sound Card 532 Plug and Play Devices 534 Managing Modules 535

  Adding a Module to the Kernel Configuration 528 Editing the Linux Kernel Configuration Files 531

  31 Managing the Kernel 527

  Maximizing Disk Space 523 Performing System Cleanups 523 Compressing Unused Documents and Directories 526

  Performing File System Maintenance 521 Deleting Unnecessary Files 521 Undeleting Files 522

  30 System Maintenance 503

  28 Managing the File System 453

  Converting Between Different Package Methods 500

  Package Management with rpm 482 The rpm Command’s Major Modes and Common Options 482 Installing Packages 483 Upgrading Packages 486 Uninstalling Packages 486 Querying Packages 488 Verifying Packages 491 Using KDE’s kPackage System to Manage RPMs 493 Installing and Using the xrpm Client 496

  29 Managing Applications 481

  Repairing File Systems 473 Disaster Recovery 476 What’s Vital and What Isn’t? 476 When to Back Up 477 What to Do with the Backups 478 Reviewing Your Backup Strategy 478 Coping with Disaster 478

  Creating New File Systems 469 How to Organize Your File System Tree 472

  Setting Up New File Systems 461 Starting linuxconf 462 linuxconf 466 Editing /etc/fstab Manually 467

  Mounting and Unmounting File Systems 454 Using the usermount Command 454 Formatting a Floppy Using the kfloppy Command 456 Using the mount Command 457

  Managing Processes 538 Using the /proc Directory Information 539 Viewing the System Load Average 540 Viewing Processes with the top Command 540

  xii Viewing Processes with the ps Command 542 Using the kill and killall Commands and Process IDs 543

  Recompiling the Kernel 545 Installing the New Kernel Source 545 Before Configuring the Kernel 546 Using make config 547 Using make xconfig 562 Building and Installing the Kernel 570 Installing the Kernel 573

  VI Appendixes

  A Resources 579

  Usenet Resources 580 World Wide Web Resources 581

  B Using Linux HOWTO Documents 585 C Top 50 Linux Commands and Utilities 597

  General Guidelines 598 The List 599 & 599 adduser 599 alias 599 apropos 600 banner 600 bg 601 bind 601 cat 601 cd 602 chgrp 602 chmod 602 chown 603 chroot 604 cp 604 dd 604 userdel 604 env 605 fc 605 fg 605 file 606 find 606 ftp 607 grep 607 groff 607 gzip 607 gunzip 608 halt 608 hostname 608 kill 608 killall 608 less 608 locate 609 login 609 logout 609 lpc 609 lpd 609 lpq 610 lpr 610 ls 610 make 611 man 611 mesg 611 mkdir 612 mkfs 612 mkswap 612 more 612 mount 612 mv 613 netstat 613 passwd 614 ps 614

  PRACTICAL Linux

  CONTENTS unalias 617 pwd 614 unzip 617 rm 614 wall 617 rmdir 615 who 617 set 615 write 618 shutdown 615 xhost 618 su 615 xmkmf 618 swapoff 616 xset 618 swapon 616 zip 619 tail 616 talk 616

  Summary 619 tar 616 telnet 616

  D Glossary 621

  top 617 umount 617

  Index 643

  About the Authors

M. Drew Streib is a senior programmer specializing in Web applications for VA

http://www.valinux.com

  Linux Systems ( ), the system administrator for Linux

  http://li.org

  International ( ), and a senior programmer for SourceForge

  http://sourceforge.net

  ( ). He also contributes to many open-source projects in his free time. Drew programs in several languages but now spends most of his time in PHP, C, and Perl. When Michael Turner was ten years old, his father bought an Apple II. Since then, not even his fianceé has managed to drag him away from behind a monitor. He cur- rently works for VA Linux Systems where his business card reads “Geek.” Michael lives in Silicon Valley, California with his fianceé, his cat, a few pet reptiles, and a home LAN that puts many corporations to shame. Michael discovered Linux and the open source movement in 1995 when he was look- ing for a cheap and reliable OS for his company’s firewall. Five years have passed and he’s proud to say that he and his fianceé run Linux on every computer and server in the house.

  John Ray is an award-winning Web application developer and network programmer

  for The Ohio State University. He holds a computer engineering degree from OSU and oversees network operations for one of its colleges. There, he implemented a campus-wide database for maintaining TCP/IP information for a wide range of net- worked computers. For the past five years, John has used Linux exclusively for his programming efforts and has championed its use for projects inside and outside the University. He provides customized Linux and UNIX-based TCP/IP programming solutions to businesses nationwide. His other publications include Sams Teach Yourself

  

Linux in 10 Minutes, Special Edition Using Red Hat Linux, Special Edition Using

TCP/IP, and Linux Maximum Security.

  Bill Ball is the author of a half-dozen best-selling books about Linux: Sams Teach

Yourself Linux in 24 Hours, Que’s Using Linux, Sams’ Red Hat Linux 6 Unleashed,

  Sams’ How to Use Linux, and Sams’ Linux Unleashed, Fourth Edition. He is a technical writer, editor, and magazine journalist and has been working with computers for the past 20 years. He first started working with Linux, beginning with kernel version .99, after moving from BSD4.3 Machten for the Apple Macintosh. He has published arti- cles in magazines such as Computer Shopper and MacTech Magazine and first started

  xiv editing books for Que in 1986. An avid fly-fisherman, he builds bamboo fly rods and fishes on the nearby Potomac River when he’s not driving his vintage MG sports car. Bill is a member of the Northern Virginia Linux Users Group (NOVALUG), and lives in the Shirlington area of Arlington County, Virginia.

  Tony Guntharp is a site manager of http://coldstorage.org for VA Linux Systems. Jan Walter is a Senior Systems Architect for the Adrenaline Group in Washington,

  D.C. He formerly consulted in the Vancouver, Canada area. His work in Vancouver included work with Internet e-commerce systems as well as support of smaller clients using Windows NT, OS/2, and of course Linux.

  Steve Shah is a systems administrator at the Center for Environmental Research

  and Technology at the University of California, Riverside. He received his B.S. in computer science with a minor in creative writing, and is currently working on his M.S. in computer science there as well. Occasionally, Steve leaves his console to pur- sue analog activities such as deejaying and spending time with his better half, Heidi.

  Sriranga Veeraraghavan works in the area of network management at Cisco

  Systems, Inc. He enjoys developing software using Java, C, Perl, and Shell for both Linux and Solaris. His pastimes include playing Marathon and debugging routing problems in his heterogeneous network at home. Sriranga graduated from the University of California at Berkeley in 1997 with an engineering degree and is pur- suing further studies at Stanford University. His most recent book is Sams Teach

  Yourself Shell Programming in 24 Hours.

  Tad Bohlsen is currently the technology manager for a nonprofit organization, and

  also a consultant on technology issues. In the past he has served as a UNIX system administrator and shell script developer, and worked with companies such as Juno Online Services and HBO.

  David Pitts has co-written more than a half-dozen books covering Linux, UNIX,

  and CGI programming in Perl. He is an author, consultant, systems administrator, programmer, instructor, Web developer, and Christian. David can be reached at

  dpitts@mk.net http://www.dpitts.com

  . His Web page, , contains more information about him. Currently, David lives in Sacramento, California with his first wife, Dana; her beautiful teen-aged cousin, Ashley; and their invisible cat, Spot. David’s favorite quote comes from Saint Francis of Assisi: “Preach the Gospel, and, if neces- sary, use words.”

  Dedication M. Drew Streib: To Dan, Patti, and Dave, who have always supported me.

  Michael Turner: I would like to thank Amy, whose support helped make the deadlines possible. xvi introduction

  inux has enjoyed incredible growth as an operating system in the

  L

  past few years. Years of refinement have helped it to grow out of a niche market and into the mainstream. You can now find Linux in mission-critical servers and on home desktops. Taking the time to learn about Linux will help increase your productivity and will enhance your overall computer experience. This book is designed for all Linux users, from Linux newcomers to seasoned system administrators. New users will want to start at the beginning and follow the tutorial-style nature of the book. More experienced users will get more out of the later book chapters. The entire book makes an excellent reference manual for common (and some not-so-common) tasks.

  Rather than choose a specific distribution for Practical Linux, we have chosen to be as distribution neutral as possible. Plenty of excellent programs are available that span all major distributions. Learning these tools ensures that you will never be locked into one company’s version of Linux. We should note, however, that some of the tasks in this book can also be accomplished with distribution-specific tools, often times more easily than with standard programs. You should learn and use these tools if they make you more productive, realizing that they might not be available in another Linux distribution. We wrote this book in a task-oriented fashion, explaining the steps required to complete each task. Learning by example can be very easy and is often the best way to understand computer skills. Practical Linux is organized in a manner that makes it a good reference.

  Part I, “Linux Basics,” introduces you to Linux, explains initial setup and use of common command-line functions and familiarizes you with the operating system.

  Part II, “Configuring Your System,” guides you through more advanced system setup, focusing on system hardware and peripheral devices.

  Linux PRACTICAL

  Part III, “The X Window System,” explains X Window, the graphical environment for Linux, including setup, configuration, and use. Part IV, “Connecting to Your Internet Service Provider,” connects you to the Internet, helping you set up your ISP connection and explaining many network pro- grams available in Linux. Part V, “System Administration,” contains advanced system setup information including user management, shell programming, and system optimization. I hope that you get as much out of Linux as I have. Open source software has shown that it can succeed in the commercial market. After you learn the basics of Linux, I would encourage you to give something back to the open source community. Programmers can of course contribute source code, but non-programmers can also play an important role by telling authors about the bugs they find, writing documen- tation, or simply telling others about what open source products work well. Enjoy this book and best wishes with your Linux experience. part

  IV I LINUX BASICS

  1

  2

  3

  4

  5

  chapter

  1 Introducing the Shell

  • Welcome to Linux
  • What is a shell?
  • Logging in to Linux
  • Logging out of Linux
  • Getting help
Congratulations on choosing and using Linux, today’s newest, most popular, flexible, and powerful free computer operating system. Hang on, because you’re riding along the crest of a rising tidal wave of new users, as Linux spreads around the globe. While governments and corporations publicly battle one another over commercial software issues, Linux has been steadily gaining worldwide acceptance and respect as a viable alternative computer operating system. Linux quietly sidesteps the restric- tions that hold commercial software hostage in the marketplace in a number of ways:

  ■

  Linux is distributed under the terms of the Free Software Foundation’s General Public License, or GPL. This license preserves software copyrights, but ensures distribution of programs with source code.

  ■ Linux is distributed over the Internet, and is easy to download, upgrade, and share. ■

  Programmers all over the world create, distribute, and maintain programs for Linux, and much of this software is also distributed under the GPL. Linux continues to evolve, and major improvements to the last several versions make using, installing, and maintaining this operating system easier than ever. With Linux’s increasing popularity, kernel bug fixes and new versions of free software appear every day on more and more Internet servers. New features of the latest ver- sions of the Linux kernel and distributions include the following:

  ■

  Support for dynamic code-module loading and unloading. If a printer or sound card is needed, the appropriate code module is loaded from a disk and then released after use as appropriate.

  ■

  Increased support for a wide variety of devices such as sound cards, scanners, hard disks, tape drives, printers, digital cameras, and joysticks.

  ■

  Increasingly easier installation, configuration, and system maintenance with dozens of different GUI (graphical user interface) programs, many of which sur- pass commercial software peers in convenience and ease of use.

  PART I Linux Basics CHAPTER 1 Introducing the Shell What is Linux? Linux is the kernel, or core, of a UNIX-like computer operating system. Linux, written by Linus Torvalds, was first released over the Internet in 1991. Since then, Linux has exploded in popularity, maturing with each new version and bug fix. When you install and use Linux, you’re installing and using a distribution, or collection of associated programs bundled with the Linux kernel. There are a number of popular Linux distributions, including Red Hat Linux, Slackware, Debian, Caldera, Mandrake, TurboLinux, and S.u.S.E. Each distribution has a different installation method and is bundled with different software maintenance tools.

6 Welcome to Linux

  PART I What Is a Shell? CHAPTER 1 There are now versions of Linux for Intel-based PCs, the Apple PowerMacintosh, Digital’s Alpha PCs, and Sun SPARC-compatibles. Each version of Linux comes

  with complete source code, so you can customize, correct bugs, or recompile the operating system.

  ➤ To learn how to rebuild the Linux kernel, see page 527.To learn how to manage kernel modules, see page 535.

  What Is a Shell?

  This chapter, which introduces you to Linux, assumes that you’ve just booted Linux for the first time after installation. The shell is a program started after you log in to Linux that provides a command-line interface between you and the Linux kernel. Typed commands are interpreted by the shell and sent to the kernel, which in turn opens, closes, reads, and writes files. There are a number of shells for Linux; the default shell for most distributions, however, is called

  bash

  and is found under the

  /bin

  directory. The shell’s internal commands and functions can also be used to write programs.

  SEE ALSOTo learn how to write shell programs, see page 323.

  ➤ To learn about how to use the shell, see page 20.

  What does open source mean anyway? The Linux operating system belongs to a genre of software called free or open source. Open-source software operates on a simple concept: Software must be accompanied with the source code that makes it work. Open- source software is synonymous with the term free software. In this case, free refers to freedom (as in “free speech” not “free beer”).

  

Shipping source code with software allows users to easily make changes, run bug fixes, install patches, and make

improvements to make the software work better. As a result, software evolves quickly and efficiently. Open-source

software taps into the brain power of developers all over the world, rather than just a few who work for any one

company. Patches and bug fixes seem to appear overnight rather than years later.

  

The open-source movement has been growing over the past 15–20 years and has now gained enough momentum

to pose a serious threat to corporate giants in the software industry. Products such as Linux, the GIMP (an image-

manipulation package), and GNU Emacs are testaments that the free software model works. For more information about open-source software, check the Web sites http://www.gnu.org and

http://www.opensource.org , or read Eric Raymond’s essay, “The Cathedral and the Bazaar” (which you

can find at http://www.tuxedo.org/~esr/writings/cathedral-bazaar/ ).

SEE ALSO

  Linux Basics

  PART I Introducing the Shell CHAPTER 1 Logging in to Linux When you sit down at your Linux terminal, the first thing you should see is a login