Statistics
68
Views
0
Downloads
0
Donations
Support
Share
Uploader

高宏飞

Shared on 2025-11-23

AuthorWilliam E. Shotts

You've experienced the shiny, point-and-click surface of your Linux computer--now dive below and explore its depths with the power of the command line. The Linux Command Line takes you from your very first terminal keystrokes to writing full programs in Bash, the most popular Linux shell (or command line). Along the way you'll learn the timeless skills handed down by generations of experienced, mouse-shunning gurus: file navigation, environment configuration, command chaining, pattern matching with regular expressions, and more. In addition to that practical knowledge, author William Shotts reveals the philosophy behind these tools and the rich heritage that your desktop Linux machine has inherited from Unix supercomputers of yore. As you make your way through the book's short, easily-digestible chapters, you'll learn how to:

Tags
No tags
ISBN: 1593279523
Publisher: No Starch Press
Publish Year: 2019
Language: 中文
Pages: 506
File Format: PDF
File Size: 7.1 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.

The Linux Command Line will take you from your first terminal keystrokes to writing full programs in the latest version of bash, the most popular Linux shell. The second edition of this worldwide best seller includes coverage of bash 4.x features like new re- direction operators and shell expansions. An updated shell scripting section discusses modern, robust shell scripting practices and ways of avoiding common types of potentially dangerous failures. As with the first edition, you’ll learn timeless command line skills like file navigation, environment configuration, command chaining, and pattern matching with regular expressions. You’ll even explore the philosophy behind the many command line tools and the rich heritage that your Linux machine inherits from Unix supercomputers of yore—all handed down by generations of mouse- shunning gurus. As you work through the book’s short, easily digestible chapters, you’ll learn how to: • Create and delete files, directories, and symlinks B A N I S H Y O U R M O U S E • Administer your system, from networking and package installation to process management • Use standard input and output, redirection, and pipelines • Edit files with vi, the world’s most popular text editor • Write shell scripts to automate common or boring tasks • Slice and dice text files with cut, paste, grep, patch, and sed Once you’ve overcome your initial “shell shock,” you’ll find that the command line is a natural and expressive way to communicate with your computer. A B O U T T H E A U T H O R William Shotts has been a software professional and avid Linux user for more than 15 years. He has an extensive background in software development, including technical support, quality assurance, and documentation. He is also the creator of LinuxCommand.org, a Linux education and advocacy site featuring news, reviews, and extensive support for using the Linux command line. SHELVE IN: COM PUTERS/LINUX $39.95 ($53.95 CDN) www.nostarch.com TH E F I N EST I N G E E K E NTE RTA I N M E NT™ OVER 100,000 COPIES SOLD A C O M P L E T E I N T R O D U C T I O N T H E L I N U X CO M M A N D L I N E W I L L I A M S H O T T S T H E L IN U X C O M M A N D L IN E T H E L IN U X C O M M A N D L IN E S H O T T S 2 N D E D I T I O N 2 N D E D I T I O N
(This page has no text content)
The LInux Command LIne
(This page has no text content)
T h e L i n u x C o m m a n d L i n e 2 n d e d i T i o n a C o m p l e t e i n t r o d u c t i o n by Wil l iam Shotts San Francisco
The Linux Command Line, 2nd ediTion. Copyright © 2019 by William Shotts. All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher. ISBN-10: 1-59327-952-3 ISBN-13: 978-1-59327-952-3 Publisher: William Pollock Production Editors: Meg Sneeringer and Serena Yang Cover Illustration: Octopod Studios Developmental Editor: Chris Cleveland Technical Reviewer: Jordi Gutiérrez Hermoso Copyeditor: Kim Wimpsett Compositors: Britt Bogan and Meg Sneeringer Proofreader: James Fraleigh For information on distribution, translations, or bulk sales, please contact No Starch Press, Inc. directly: No Starch Press, Inc. 245 8th Street, San Francisco, CA 94103 phone: 1.415.863.9900; info@nostarch.com www.nostarch.com The Library of Congress issued the following Cataloging-in-Publication Data for the first edition: Shotts, William E. The Linux command line: a complete introduction / William E. Shotts, Jr. p. cm. Includes index. ISBN-13: 978-1-59327-389-7 (pbk.) ISBN-10: 1-59327-389-4 (pbk.) 1. Linux. 2. Scripting Languages (Computer science) 3. Operating systems (Computers) I. Title. QA76.76.O63S5556 2011 005.4'32--dc23 2011029198 No Starch Press and the No Starch Press logo are registered trademarks of No Starch Press, Inc. Other product and company names mentioned herein may be the trademarks of their respective owners. Rather than use a trademark symbol with every occurrence of a trademarked name, we are using the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The information in this book is distributed on an “As Is” basis, without warranty. While every precaution has been taken in the preparation of this work, neither the author nor No Starch Press, Inc. shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in it.
To Karen
(This page has no text content)
About the Author William Shotts has been a software professional for more than 30 years and an avid Linux user for more than 20 years. He has an extensive background in software development, including technical support, quality assurance, and documentation. He is also the creator of LinuxCommand.org, a Linux education and advocacy site featuring news, reviews, and extensive support for using the Linux command line. About the Technical Reviewer Jordi Gutiérrez Hermoso is a coder, mathematician, and hacker-errant. He runs Debian GNU/Linux exclusively since 2002, both at home and at work. Jordi has been involved with GNU Octave, a free numerical computing envi- ronment largely compatible with Matlab, and with Mercurial, a distributed version control system. He enjoys pure and applied mathematics, skating, swimming, and knitting. Nowadays he thinks a lot about environmental mapping, greenhouse gas emissions, and rhino conservation efforts.
(This page has no text content)
B r i e f C o n t e n t s Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xxiii Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxv PART I: LEARNING THE SHELL Chapter 1: What Is the Shell? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Chapter 2: Navigation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 Chapter 3: Exploring the System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 Chapter 4: Manipulating Files and Directories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 Chapter 5: Working with Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 Chapter 6: Redirection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 Chapter 7: Seeing the World as the Shell Sees It . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 Chapter 8: Advanced Keyboard Tricks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73 Chapter 9: Permissions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 Chapter 10: Processes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 PART II: CONFIGURATION AND THE ENVIRONMENT Chapter 11: The Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115 Chapter 12: A Gentle Introduction to vi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127 Chapter 13: Customizing the Prompt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145 PART III: COMMON TASKS AND ESSENTIAL TOOLS Chapter 14: Package Management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155 Chapter 15: Storage Media . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165 Chapter 16: Networking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181 Chapter 17: Searching for Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195 Chapter 18: Archiving and Backup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209
x Brief Contents Chapter 19: Regular Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225 Chapter 20: Text Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245 Chapter 21: Formatting Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279 Chapter 22: Printing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297 Chapter 23: Compiling Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 309 PART IV: WRITING SHELL SCRIPTS Chapter 24: Writing Your First Script . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 323 Chapter 25: Starting a Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 329 Chapter 26: Top-Down Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 339 Chapter 27: Flow Control: Branching with if . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 349 Chapter 28: Reading Keyboard Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 363 Chapter 29: Flow Control: Looping with while/until . . . . . . . . . . . . . . . . . . . . . . . . . 375 Chapter 30: Troubleshooting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 383 Chapter 31: Flow Control: Branching with case . . . . . . . . . . . . . . . . . . . . . . . . . . . . 395 Chapter 32: Positional Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 401 Chapter 33: Flow Control: Looping with for . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 413 Chapter 34: Strings and Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 419 Chapter 35: Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 437 Chapter 36: Exotica . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 447 Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 459
C o n t e n t s i n D e t a i l Acknowledgments xxiii First Edition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xxiii Second Edition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xxiv IntroductIon xxv Why Use the Command Line? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xxvi What This Book Is About . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xxvi Who Should Read This Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxvii What’s in This Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxvii How to Read This Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxviii Prerequisites . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxviii What’s New in the Second Edition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xxix Your Feedback Is Needed! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxx PArt I: leArnIng tHe sHell 1 wHAt Is tHe sHell? 3 Terminal Emulators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Making Your First Keystrokes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 Command History . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 Cursor Movement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 Try Some Simple Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 Ending a Terminal Session . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 Summing Up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 2 nAvIgAtIon 7 Understanding the File System Tree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 The Current Working Directory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 Listing the Contents of a Directory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 Changing the Current Working Directory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 Absolute Pathnames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 Relative Pathnames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 Some Helpful Shortcuts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 Summing Up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
xii Contents in Detail 3 exPlorIng tHe system 13 More Fun with ls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 Options and Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 A Longer Look at Long Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 Determining a File’s Type with file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 Viewing File Contents with less . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 Taking a Guided Tour . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 Symbolic Links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 Hard Links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 Summing Up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 4 mAnIPulAtIng FIles And dIrectorIes 23 Wildcards . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 mkdir—Create Directories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 cp—Copy Files and Directories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 Useful Options and Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 mv—Move and Rename Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 Useful Options and Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 rm—Remove Files and Directories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 Useful Options and Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 ln—Create Links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 Hard Links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 Symbolic Links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 Building a Playground . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 Creating Directories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 Copying Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 Moving and Renaming Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 Creating Hard Links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 Creating Symbolic Links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 Removing Files and Directories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 Summing Up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 5 workIng wItH commAnds 39 What Exactly Are Commands? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 Identifying Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 type—Display a Command’s Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 which—Display an Executable’s Location . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 Getting a Command’s Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 help—Get Help for Shell Builtins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 --help—Display Usage Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 man—Display a Program’s Manual Page . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 apropos—Display Appropriate Commands . . . . . . . . . . . . . . . . . . . . . . . . . 44 whatis—Display One-line Manual Page Descriptions . . . . . . . . . . . . . . . . . . . 44 info—Display a Program’s Info Entry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 README and Other Program Documentation Files . . . . . . . . . . . . . . . . . . . . 46
Contents in Detail xiii Creating Our Own Commands with alias . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 Summing Up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 6 redIrectIon 49 Standard Input, Output, and Error . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 Redirecting Standard Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 Redirecting Standard Error . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52 Redirecting Standard Output and Standard Error to One File . . . . . . . . . . . . . 52 Disposing of Unwanted Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 Redirecting Standard Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 cat: Concatenate Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 Pipelines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55 Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55 uniq: Report or Omit Repeated Lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 wc: Print Line, Word, and Byte Counts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 grep: Print Lines Matching a Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 head/tail: Print First/Last Part of Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 tee: Read from Stdin and Output to Stdout and Files . . . . . . . . . . . . . . . . . . . 59 Summing Up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 7 seeIng tHe world As tHe sHell sees It 61 Expansion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 Pathname Expansion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62 Tilde Expansion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 Arithmetic Expansion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64 Brace Expansion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 Parameter Expansion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66 Command Substitution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 Quoting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 Double Quotes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68 Single Quotes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 Escaping Characters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70 Backslash Escape Sequences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70 Summing Up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71 8 AdvAnced keyboArd trIcks 73 Command Line Editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74 Cursor Movement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74 Modifying Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74 Cutting and Pasting (Killing and Yanking) Text . . . . . . . . . . . . . . . . . . . . . . . 75 Completion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76 Using History . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77 Searching History . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77 History Expansion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79 Summing Up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
xiv Contents in Detail 9 PermIssIons 81 Owners, Group Members, and Everybody Else . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82 Reading, Writing, and Executing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 chmod: Change File Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 Setting File Mode with the GUI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88 umask: Set Default Permissions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89 Some Special Permissions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 Changing Identities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91 su: Run a Shell with Substitute User and Group IDs . . . . . . . . . . . . . . . . . . . . 92 sudo: Execute a Command As Another User . . . . . . . . . . . . . . . . . . . . . . . . . 93 chown: Change File Owner and Group . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94 chgrp: Change Group Ownership . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95 Exercising Our Privileges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95 Changing Your Password . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97 Summing Up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98 10 Processes 99 How a Process Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 Viewing Processes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 Viewing Processes Dynamically with top . . . . . . . . . . . . . . . . . . . . . . . . . . 102 Controlling Processes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104 Interrupting a Process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105 Putting a Process in the Background . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105 Returning a Process to the Foreground . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106 Stopping (Pausing) a Process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106 Signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 Sending Signals to Processes with kill . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 Sending Signals to Multiple Processes with killall . . . . . . . . . . . . . . . . . . . . . 109 Shutting Down the System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110 More Process-Related Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111 Summing Up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111 PArt II: conFIgurAtIon And tHe envIronment 11 tHe envIronment 115 What Is Stored in the Environment? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116 Examining the Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116 Some Interesting Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117 How Is the Environment Established? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118 What’s in a Startup File? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119 Modifying the Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121 Which Files Should We Modify? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121 Text Editors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
Contents in Detail xv Using a Text Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122 Activating Our Changes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125 Summing Up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125 12 A gentle IntroductIon to vI 127 Why We Should Learn vi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128 A Little Background . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128 Starting and Stopping vi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128 Editing Modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130 Entering Insert Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131 Saving Our Work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131 Moving the Cursor Around . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131 Basic Editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132 Appending Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132 Opening a Line . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133 Deleting Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134 Cutting, Copying, and Pasting Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135 Joining Lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136 Search-and-Replace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136 Searching Within a Line . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137 Searching the Entire File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137 Global Search-and-Replace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137 Editing Multiple Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139 Switching Between Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139 Opening Additional Files for Editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140 Copying Content from One File into Another . . . . . . . . . . . . . . . . . . . . . . . 141 Inserting an Entire File into Another . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141 Saving Our Work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142 Summing Up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143 13 customIzIng tHe PromPt 145 Anatomy of a Prompt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145 Trying Some Alternative Prompt Designs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147 Adding Color . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148 Moving the Cursor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150 Saving the Prompt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151 Summing Up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151 PArt III: common tAsks And essentIAl tools 14 PAckAge mAnAgement 155 Packaging Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156 How a Package System Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156 Package Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156 Repositories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
xvi Contents in Detail Dependencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157 High- and Low-Level Package Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158 Common Package Management Tasks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158 Finding a Package in a Repository . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158 Installing a Package from a Repository . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159 Installing a Package from a Package File . . . . . . . . . . . . . . . . . . . . . . . . . . 159 Removing a Package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160 Updating Packages from a Repository . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160 Upgrading a Package from a Package File . . . . . . . . . . . . . . . . . . . . . . . . 160 Listing Installed Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161 Determining Whether a Package Is Installed . . . . . . . . . . . . . . . . . . . . . . . . 161 Displaying Information About an Installed Package . . . . . . . . . . . . . . . . . . . 161 Finding Which Package Installed a File . . . . . . . . . . . . . . . . . . . . . . . . . . . 162 Summing Up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162 15 storAge medIA 165 Mounting and Unmounting Storage Devices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166 Viewing a List of Mounted File Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . 167 Determining Device Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170 Creating New File Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173 Manipulating Partitions with fdisk . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173 Creating a New File System with mkfs . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175 Testing and Repairing File Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176 Moving Data Directly to and from Devices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177 Creating CD-ROM Images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177 Creating an Image Copy of a CD-ROM . . . . . . . . . . . . . . . . . . . . . . . . . . . 177 Creating an Image from a Collection of Files . . . . . . . . . . . . . . . . . . . . . . . 178 Writing CD-ROM Images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178 Mounting an ISO Image Directly . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179 Blanking a Rewritable CD-ROM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179 Writing an Image . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179 Summing Up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179 Extra Credit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180 16 networkIng 181 Examining and Monitoring a Network . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182 ping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182 traceroute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183 ip . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184 netstat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184 Transporting Files over a Network . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185 ftp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186 lftp—a Better ftp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187 wget . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188 Secure Communication with Remote Hosts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188 ssh . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188 scp and sftp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192 Summing Up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193
Contents in Detail xvii 17 seArcHIng For FIles 195 locate—Find Files the Easy Way . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196 find—Find Files the Hard Way . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197 Tests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198 Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200 Predefined Actions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202 User-Defined Actions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204 Improving Efficiency . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204 xargs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205 A Return to the Playground . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206 find Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208 Summing Up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208 18 ArcHIvIng And bAckuP 209 Compressing Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210 gzip . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210 bzip2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212 Archiving Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213 tar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213 zip . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217 Synchronizing Files and Directories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219 Using rsync over a Network . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222 Summing Up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223 19 regulAr exPressIons 225 What Are Regular Expressions? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226 grep . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226 Metacharacters and Literals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227 The Any Character . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228 Anchors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228 Bracket Expressions and Character Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230 Negation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230 Traditional Character Ranges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230 POSIX Character Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231 POSIX Basic vs . Extended Regular Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234 Alternation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235 Quantifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236 ? —Match an Element Zero or One Time . . . . . . . . . . . . . . . . . . . . . . . . . . 236 *—Match an Element Zero or More Times . . . . . . . . . . . . . . . . . . . . . . . . . 237 +—Match an Element One or More Times . . . . . . . . . . . . . . . . . . . . . . . . . 238 { }—Match an Element a Specific Number of Times . . . . . . . . . . . . . . . . . . . 238 Putting Regular Expressions to Work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239 Validating a Phone List with grep . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239 Finding Ugly Filenames with find . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 240 Searching for Files with locate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241 Searching for Text with less and vim . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241 Summing Up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242
xviii Contents in Detail 20 text ProcessIng 245 Applications of Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246 Documents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246 Web Pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246 Email . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246 Printer Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246 Program Source Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247 Revisiting Some Old Friends . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247 cat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247 sort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248 uniq . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254 Slicing and Dicing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256 cut—Remove Sections from Each Line of Files . . . . . . . . . . . . . . . . . . . . . . . 256 paste—Merge Lines of Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 258 join—Join Lines of Two Files on a Common Field . . . . . . . . . . . . . . . . . . . . 260 Comparing Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262 comm—Compare Two Sorted Files Line by Line . . . . . . . . . . . . . . . . . . . . . 262 diff—Compare Files Line by Line . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263 patch—Apply a diff to an Original . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265 Editing on the Fly . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266 tr—Transliterate or Delete Characters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266 sed—Stream Editor for Filtering and Transforming Text . . . . . . . . . . . . . . . . 268 aspell—Interactive Spellchecker . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275 Summing Up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 278 Extra Credit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 278 21 FormAttIng outPut 279 Simple Formatting Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 280 nl—Number Lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 280 fold—Wrap Each Line to a Specified Length . . . . . . . . . . . . . . . . . . . . . . . . 282 fmt—A Simple Text Formatter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283 pr—Format Text for Printing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 286 printf—Format and Print Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287 Document Formatting Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290 groff . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290 Summing Up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295 22 PrIntIng 297 A Brief History of Printing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 298 Printing in the Dim Times . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 298 Character-Based Printers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 298 Graphical Printers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299 Printing with Linux . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 300 Preparing Files for Printing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 300 pr—Convert Text Files for Printing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 300