Publisher : O'ReillyPub Date : November 2004ISBN : 0-596-00640-3Pages : 580 Linux information can be found scattered in man pages, texinfo files, and source code comments, but the best s
Trang 1Publisher : O'ReillyPub Date : November 2004ISBN : 0-596-00640-3Pages : 580
Linux information can be found scattered in man pages, texinfo files, and source code comments, but the best source is the experts who have built up a working knowledge of managing
Linux systems The Linux Cookbook's tested techniques distill
years of hard-won experience into practical cut-and-paste solutions to everyday Linux dilemmas Use just one recipe from this collection of real-world solutions, and the hours of tedious trial-and-error saved will more than pay for the cost of the book It's more than a time-saver; it's a sanity saver.
Trang 2Publisher : O'ReillyPub Date : November 2004ISBN : 0-596-00640-3Pages : 580
Trang 14Printed in the United States of America
Published by O'Reilly Media, Inc., 1005 Gravenstein HighwayNorth, Sebastopol, CA 95472
O'Reilly books may be purchased for educational, business, orsales promotional use Online editions are also available for
most titles (http://safari.oreilly.com) For more information,contact our corporate/institutional sales department: (800)
While every precaution has been taken in the preparation of thisbook, the publisher and author assume no responsibility for
errors or omissions, or for damages resulting from the use ofthe information contained herein
Trang 15To Dawn Marie.
During the writing of this book, she tilled the fields, trained the horses, cooked the meals, cleaned the ditches, and graciously fended off generous neighbors bearing large zucchinis No
author could ask for more Thank you for 14 great years; may
we have many more.
Trang 16So: you're a relatively new Linux user You've got Linux
installed, you've managed to log in, do some web browsing,send and receive email, andnow what? Although you can handlesome of the basics, you feel like you're flying blind: you knowyou've got lots of really powerful stuff at your fingertips, or atleast so your Linux guru friend told you, but how do you make it
do tricks? What's there, and how does it work? What's this thingcalled grep that they're always talking about? How do you
Samba? And where's the #$%^ documentation?
The Linux-Unix world is abundantly documented No, really! Youcan always find an answer, if you know where to look The
problem, of course, is knowing where to look There are manpages, info pages, READMEs, HTML manuals, and the code
itself You don't have to be a programmer to unearth useful bits
in source code, because the comments often tell you what youneed to know
There are thousands upon thousands of online communities,one (or more) surrounding nearly every bit of software in theLinux universe Nearly every program, no matter how small,has its own user mailing list Every Linux distribution has itsown mailing lists and user forums There are forums and listsand Usenet groups for every computing subject under the sun
And of course there are books and magazines of every
description So the real problem with Linux documentation isnot the lack of it, but finding the bits you need without having
to embark on a lengthy, heroic quest
Trang 17This book is aimed at folks who want to know what button topush Understanding the underlying theory is useful, but if youcan't make the darn thing work, not very helpful So it's light ontheory and heavy on how-to-make-this-go, with detailed, step-by-step instructions I've included many references to additionalresources
Readers should have a bit of Linux experience You don't need
to be a guru, but you should have some familiarity with the
basics of booting up and shutting down, starting applications,Web surfing, and poking around the filesystem You should
know how to find and use the command line, as well as work in
a graphical environment You should understand that Linux is atrue multi-user system, and that you use an ordinary
unprivileged user account as much as possible, and that youonly invoke root when you really need to
This book assumes that you are in charge of a PC or LAN, andcan acquire rootly powers when the occasion calls for them Youmight be a power user who wants complete control of your
Linux box, or a home user who wants to run a personal web ormail server, or set up a small LAN Perhaps you are a Windowssystem admininstrator who has suddenly been ordered to "doLinux," and you need to know how to set up Linux servers forWindows clients Maybe you want to add Linux servers to anexisting network You might need to integrate Linux and
Windows desktop users on a LAN
Or you have no need for Windows at all, and just want to learnLinux system administration
Trang 18Given that there are thousands of software packages to choosefrom, almost all of which do something useful, it was a foregoneconclusion that I couldn't cover everything Or even most ofeverything I decided what to include, and what to leave out,based on my opinion of what a fundamental Linux skill set
should include (You may have different ideas.) I included
programs that I consider to be the best-of-breed, such djbdns,GRUB, Apache 2, vim, and Postfix And I didn't neglect old
Linux system, it will take you anywhere you want to go
Trang 19There are more Linux distributions than can be counted; thereare literally thousands of distributions, many of which are
peculiar to a company, a campus, or even a circle of friends wholike to roll their own However, the world of distributions breaks(not very cleanly) into two large camps: RPM-based systems,represented in this book by Red Hat and Fedora, and apt-basedsystems, represented by Debian Debian-based distributions arespreading like weeds, such as Knoppix, Xandros, Libranet,
Unbuntu, and Linspire
Even if you are using a distribution that does not fall into one ofthese two categories, such as Slackware or Gentoo, the
fundamentals are pretty much the same The kernel is the
same; the programs and utilities available are the same; thewindow managers are the same; the only substantial difference
is the way you install software
That's not to say there aren't other differences between Linuxdistributions A chronic bugaboo with Linux is differing file
locations on different distributions Get used to it; it's not going
to go away This book provides several excellent methods forfinding out where your particular distribution puts configurationfiles, executables, and program documentation
Trang 21One particularly important convention in this book involves theuse of command line prompts I can't say it too often: don't getinto the habit of su'ing to root whenever you have to do
anything remotely administrative Even worse, don't say "It's
my machine, I can do anything as root." Use root privilegesonly when you really need them You'll be safer that way; you'llhave some protection against your own mistakes, and againstattacks made by outsiders
To show you when you need root privileges, commands
requiring root privileges are preceded by the root prompt, #.Commands that don't require root privileges are preceded bythe default bash shell prompt, $
Don't be confusedthere are many file listings in the book, and inmany of these files, comments are preceded by # Yes, it can
be confusing, but you'll get used to it
Trang 22Doubtless this book, despite the heroic efforts of me and thefabulous O'Reilly team, contains flaws, errors, and omissions.Please email your feedback and suggestions to
cookbook@bratgrrl.com, so we can make the second editioneven better Be sure to visit http://tuxcomputing.com for
errata, updates, and to download the scripts and configurationfiles used in the book
This book was authored entirely in Open Office Writer, on
Libranet Debian 2.8
Trang 23Please address comments and questions concerning this book tothe publisher:
To comment on or ask technical questions about this book, sendemail to:
bookquestions@oreilly.com
For more information about books, conferences, software,
Resource Centers, and the O'Reilly Network, see the O'Reillyweb site at:
http://www.oreilly.com
Trang 24Thank you to ace O'Reilly editor Michael Loukides, whose goodtaste, eagle editorial eye, patient endurance, and implacableinsistence made this a much better book
Thank you to ace technical reviewer Jenn Vesperman, and herattention to detail Silly computers are completely literal, andmust be fed precise inputthanks Jenn!
Many thanks to Akkana Peck, Jenn Vesperman, Paul Heinlein,and Peter Samuelson, whose contributions appear in this book.Heartfelt thanks to the gang at Linuxchix, including Jenn
Vesperman (benevolent dictator of Linuxchix), Dancer
Vesperman, Danamania (the camera does not lie), Colby,
Evilpig, Almut Behrens, Andrew (Mandrake Guru), Hamster,Piglet, Val Henson (uppity rabble rouser), H Peter Anvin (kernelguru and rabbit rouser), Rik Rose, Devdas Bhagat, David North(for comic relief), Telsa Gwynne, Maria Blackmore, MeredyddLuff, Kai MacTane, and Erinn Clark (for more uppity rabble-
rousing) Linuxchix rawks!
I'm sure I missed some folks who patiently endured my endlesspestering Tell me who you are, and I'll fix it in the second
edition
Trang 26Documentation for Linux programs is abundant Finding it can
be a bit challenging, though You're not going to find lots ofsleek, glossy printed manuals, because most Linux software isdistributed online, rather than in shiny boxed sets
There's another difficulty, too: Linux follows the grand Unix
tradition of small, specialized programs working cooperatively,
so any Linux distribution contains a large number of individualprograms For example, Tom's Root Boot, "The most GNU/Linux
on one floppy disk," contains over 230 separate, individual
programs on a single 3.5" diskette A general-purpose
distribution such as Mandrake or SuSE contains several
thousand programs and there are over 12,000 packages in theDebian repositories While organizing and maintaining a printedlibrary presents some difficulties, the good news is that all ofthese things are documented Whatever you want to know,
there is a way to find it
1.1.1 man and info: The Universal Linux Manuals
Almost every program written for Linux has a man page.
They're usually not the best teaching tool for newbies Theirpurpose is to document the command syntax and every
command option, and to be universally available No matterwhat kind of strange desert-island scenario you may find
yourself in, there will always be man pages And because manpages are incorporated into the programs to which they belong,you'll find that only installed programs have man pages andthat the versions of those pages are pertinent to your system
info pages tend to be more verbose than man pages and are
hyperlinked The hyperlinks navigate to the various nodes, or
Trang 271.1.2 Other Documentation
A large number of README, CHANGELOGS, RELEASE NOTES,COPYRIGHT, INSTALL, integrated Help systems, and HTML docsare going to be squirreled away in various locations on yoursystem Yes, it's a jumble Don't worry, you'll learn easy ways
to find all these things in this chapter, including a nice Pythonscript to do the finding for you
There are many web sites that host complete archives of manand info pages, which comes in handy if your system is missingthe ones you want, or you want to read them without having todownload and install new programs A Google search will findthem quickly
The commercial Linux distributionsfor example, Red Hat, SuSE,Mandrake, Xandros, and Linspiresupply excellent user manuals.Every major Linux distribution provides a feast of online
resources Search engines, user mailing lists, Usenet, and allsorts of Linux web sites also supply a wealth of help and
information
1.1.3 Graphical Viewers
There are several good graphical man and info page viewers:
Konqueror
Trang 28man and info page viewer Simply type man:foo or info:/foo
in the address bar It is easy to print from Konqueror, andeasy to select individual man or info pages for printing
Trang 29Learn how man pages are organized, and familiarize yourselfwith their conventions for teaching command syntax and
options, and you'll find that man pages really are helpful
1.2.3 Discussion
Linux sees all the man pages on a system as part of a singlemanual This manual is divided into sections:
Trang 30OPTIONS, FILES, EXAMPLES, SEE ALSO, BUGS, and AUTHOR
Here's the notation used to show command syntax, found in theSynopsis of the man pages:
command-name [optional flags] any-other-required-elements
Trang 31Everything inside square brackets is optional and can becombined
[-a|-b|-c]
Options separated by the pipe | (Shift-backslash) cannot becombined
argument
The ellipsis indicates that several arguments can be listed.Watch out for delimitersusually they are spaces, but
sometimes commas are used
Trang 33pwconv (8) - convert to and from shadow passwords and groups
Trang 35apropos(1), man(1)
Trang 38.SH SYNOPSIS
.B cat
Trang 391.5.4 See Also
mandb(8), locate(1), grep(1), nroff(1), groff(1), zless(1), zcat(1)
Recipe 1.6
Chapter 9 of Running Linux, by Matt Walsh, Matthias
Dalheimer, Terry Dawson, and Lar Kaufman (O'Reilly)
Trang 401.6.1 Problem
You're repeatedly having trouble finding man pages; using toolsfrom Recipe 1.4, you find that most of the missing pages are in
Trang 41You can run manpath with no options to see your current
manpaths:
Trang 42/usr/local/man:/usr/share/man:/usr/X11R6/man:/usr/man
1.6.4 See Also
manpath(1), manpath(5)
Trang 431.7.3 Discussion
Even though some folks think that info pages are unnecessarilycomplicated to navigate, it is worth getting acquainted with
them Even though they are more difficult to navigate than manpages, they are (usually) easier to understand Once you getthe hang of moving around in them, you can go very fast andfind information quickly Info pages often contain more
information than man pages, and they sometimes include
tutorials and extensive examples
There are also a number of nice info viewers, such as pinfo,
Konqueror, and Yelp Pinfo runs in the console, and Konquerorand Yelp need X Konqueror is especially easy to navigate and
to use for printing selected pages
Trang 44info info
Trang 451.8.1 Problem
You want to print a man page, nicely formatted and readable You have tried man foo | lpr, but it doesn't look very good The
margins are too small, and all the formatting is lost
1.8.2 Solution
One way to print a nicely formatted man page is to use the -t flag, which formats it especially for printing man finger is good
choice:
Trang 49Recipe 1.10 Printing Selected man or info Pages 1.10.1 Problem
of reverse line feeds, which then appear in text files as eitherempty boxes or repeated characters
Trang 50col(1)
Trang 51Recipe 1.11 Finding All of the Documentation for a Program
1.11.1 Problem
You want to find all the relevant readmes, changelogs, howtos,guides, examples, samples, and other documentation that
Trang 54]
Trang 55
#print path
Trang 57
if (re.compile(nam).search(base, 1)) : print path,
Trang 58Recipe 2.8 Rebuilding the RPM Database
Based System
Recipe 2.9 Tracking Source-Built Libraries on an RPM-Recipe 2.10 Fixing RPM Installation Problems
Recipe 2.11 Installing Source RPMs
Recipe 2.12 Customizing Build Options in a Source RPMRecipe 2.13 Installing Yum
Recipe 2.14 Configuring Yum
Recipe 2.15 Installing and Upgrading Packages with YumRecipe 2.16 Removing Packages with Yum