Praise for the First Edition of A Practical Guide to Linux Commands, Editors, and Shell Programming ® “This book is a very useful tool for anyone who wants to ‘look under the hood’ so to speak, and really start putting the power of Linux to work. What I find particularly frustrating about man pages is that they never include examples. Sobell, on the other hand, outlines very clearly what the command does and then gives several common, easy-to- understand examples that make it a breeze to start shell programming on one’s own. As with Sobell’s other works, this is simple, straight-for- ward, and easy to read. It’s a great book and will stay on the shelf at easy arm’s reach for a long time.” —Ray Bartlett Travel Writer “Overall I found this book to be quite excellent, and it has earned a spot on the very front of my bookshelf. It covers the real ‘guts’ of Linux— the command line and its utilities—and does so very well. Its strongest points are the outstanding use of examples, and the Command Refer- ence section. Highly recommended for Linux users of all skill levels. Well done to Mark Sobell and Prentice Hall for this outstanding book!” —Dan Clough Electronics Engineer and Slackware Linux user “Totally unlike most Linux books, this book avoids discussing every- thing via GUI and jumps right into making the power of the command line your friend.” —Bjorn Tipling Software Engineer ask.com “This book is the best distro-agnostic, foundational Linux reference I’ve ever seen, out of dozens of Linux-related books I’ve read. Finding this book was a real stroke of luck. If you want to really understand how to get things done at the command line, where the power and flexibility of free UNIX-like OSes really live, this book is among the best tools you’ll find toward that end.” —Chad Perrin Writer, TechRepublic Praise for Other Books by Mark G. Sobell “I keep searching for books that collect everything you want to know about a subject in one place, and keep getting disappointed. Usually the books leave out some important topic, while others go too deep in some areas and must skim lightly over the others. A Practical Guide to Red Hat® Linux® is one of those rare books that actually pulls it off. Mark G. Sobell has created a single reference for Red Hat Linux that can’t be beat! This marvelous text (with a 4-CD set of Linux Fedora Core 2 included) is well worth the price. This is as close to an ‘every- thing you ever needed to know’ book that I’ve seen. It’s just that good and rates 5 out of 5.” —Ray Lodato Slashdot contributor “Mark Sobell has written a book as approachable as it is authoritative.” —Jeffrey Bianchine Advocate, Author, Journalist “Excellent reference book, well suited for the sysadmin of a Linux clus- ter, or the owner of a PC contemplating installing a recent stable Linux. Don’t be put off by the daunting heft of the book. Sobell has strived to be as inclusive as possible, in trying to anticipate your system adminis- tration needs.” —Wes Boudville Inventor “A Practical Guide to Red Hat® Linux® is a brilliant book. Thank you Mark Sobell.” —C. Pozrikidis University of California at San Diego “This book presents the best overview of the Linux operating system that I have found. . . . [It] should be very helpful and understandable no matter what the reader’s background: traditional UNIX user, new Linux devotee, or even Windows user. Each topic is presented in a clear, complete fashion, and very few assumptions are made about what the reader knows. . . . The book is extremely useful as a reference, as it contains a 70-page glossary of terms and is very well indexed. It is organized in such a way that the reader can focus on simple tasks with- out having to wade through more advanced topics until they are ready.” —Cam Marshall Marshall Information Service LLC Member of Front Range UNIX Users Group [FRUUG] Boulder, Colorado “Conclusively, this is THE book to get if you are a new Linux user and you just got into the RH/Fedora world. There’s no other book that dis- cusses so many different topics and in such depth.” —Eugenia Loli-Queru Editor in Chief OSNews.com This page intentionally left blank A Practical Guide to Linux Commands, ® Editors, and Shell Programming SECOND EDITION This page intentionally left blank A Practical Guide to Linux Commands, ® Editors, and Shell Programming SECOND EDITION Mark G. Sobell Upper Saddle River, NJ • Boston • Indianapolis • San Francisco New York • Toronto • Montreal • London • Munich • Paris • Madrid Capetown • Sydney • Tokyo • Singapore • Mexico City 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 the publisher was aware of a trademark claim, the designations have been printed with initial capital letters or in all capitals. The author and publisher have taken care in the preparation of this book, but make no expressed or implied warranty of any kind and assume no responsibility for errors or omissions. No liability is assumed for incidental or consequential damages in connection with or arising out of the use of the information or programs contained herein. The publisher offers excellent discounts on this book when ordered in quantity for bulk purchases or special sales, which may include electronic versions and/or custom covers and content particular to your business, training goals, marketing focus, and branding interests. For more information, please contact: U.S. Corporate and Government Sales (800) 382-3419 [email protected] For sales outside the United States, please contact: International Sales [email protected] Visit us on the Web: informit.com/ph Library of Congress Cataloging-in-Publication Data Sobell, Mark G. A practical guide to Linux commands, editors, and shell programming / Mark G. Sobell.—2nd ed. p. cm. Includes bibliographical references and index. ISBN 978-0-13-136736-4 (pbk.) 1. Linux. 2. Operating systems (Computers) I. Title. QA76.76.O63S59483 2009 005.4'32—dc22 2009038191 Copyright © 2010 Mark G. Sobell All rights reserved. Printed in the United States of America. This publication is protected by copyright, and permission must be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permissions, write to: Pearson Education, Inc. Rights and Contracts Department 501 Boylston Street, Suite 900 Boston, MA 02116 Fax: (617) 671-3447 ISBN-13: 978-0-13-136736-4 ISBN-10: 0-13-136736-6 Text printed in the United States at Edwards Brothers in Ann Arbor, Michigan. First printing, October 2009 With love for my guys, Zach, Max, and Sam