Table Of ContentFedora®Linux®
TOOLBOX
1000+ Commands for Fedora, CentOS,
and Red Hat® Power Users
Christopher Negus
François Caen
Wiley Publishing, Inc.
82911ffirs.qxd:Toolbox 10/19/07 12:41 PM Page iii
Fedora® Linux® Toolbox:
1000+ Commands for Fedora, CentOS, and Red Hat® Power Users
Published by
Wiley Publishing, Inc.
10475 Crosspoint Boulevard
Indianapolis, IN 46256
www.wiley.com
Copyright © 2008 by Wiley Publishing, Inc., Indianapolis, Indiana
Published simultaneously in Canada
ISBN: 978-0-470-08291-1
Manufactured in the United States of America
10 9 8 7 6 5 4 3 2 1
Library of Congress Cataloging-in-Publication Data
Negus, Chris, 1957–
Fedora Linux toolbox : 1000+ commands for Fedora, Centos and Red Hat power users / Christopher
Negus, François Caen.
p. cm.
Includes index.
ISBN 978-0-470-08291-1 (pbk.)
1. Linux. 2. Operating systems (Computers) I. Caen, François. II. Title.
QA76.76.O63N4185 2007
005.4'32—dc22
2007039391
No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by
any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under
Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the
Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center,
222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permis-
sion should be addressed to the Legal Department, Wiley Publishing, Inc., 10475 Crosspoint Blvd., Indianapolis,
IN 46256, (317) 572-3447, fax (317) 572-4355, or online at http://www.wiley.com/go/permissions.
Limit of Liability/Disclaimer of Warranty: The publisher and the author make no representations or warranties
with respect to the accuracy or completeness of the contents of this work and specifically disclaim all warranties,
including without limitation warranties of fitness for a particular purpose. No warranty may be created or
extended by sales or promotional materials. The advice and strategies contained herein may not be suitable for
every situation. This work is sold with the understanding that the publisher is not engaged in rendering legal,
accounting, or other professional services. If professional assistance is required, the services of a competent pro-
fessional person should be sought. Neither the publisher nor the author shall be liable for damages arising here-
from. The fact that an organization or Website is referred to in this work as a citation and/or a potential source of
further information does not mean that the author or the publisher endorses the information the organization or
Website may provide or recommendations it may make. Further, readers should be aware that Internet Websites
listed in this work may have changed or disappeared between when this work was written and when it is read.
For general information on our other products and services please contact our Customer Care Department
within the United States at (800) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002.
Trademarks: Wiley and the Wiley logo are trademarks or registered trademarks of John Wiley & Sons, Inc.
and/or its affiliates, in the United States and other countries, and may not be used without written permission.
Red Hat and Fedora are registered trademarks of Red Hat, Inc. Linux is a registered trademark of Linus Torvalds.
All other trademarks are the property of their respective owners. Wiley Publishing, Inc. is not associated with any
product or vendor mentioned in this book.
Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be
available in electronic books.
82911ffirs.qxd:Toolbox 10/19/07 12:41 PM Page iv
As always, I dedicate my work on this book to my wife, Sheree.
— Christopher Negus
To my dad, for teaching me BASIC when I was little.
— François Caen
82911ffirs.qxd:Toolbox 10/19/07 12:41 PM Page v
82911ffirs.qxd:Toolbox 10/19/07 12:41 PM Page vi
About the Authors
Christopher Negus is the author of the best-selling Fedora and Red Hat Linux Bibles,
Linux Toys, Linux Troubleshooting Bible, and Linux Bible 2007 Edition. He is a member of
the Madison Linux Users Group. Prior to becoming a full-time writer, Chris served
for eight years on development teams for the Unix operating system at AT&T, where
Unix was created and developed. He also worked with Novell on Unix development
and Caldera Linux.
François Caen, through his company Turbosphere LLC, hosts and manages business
application infrastructures, with 95 percent running on Linux systems. As an open
source advocate, he has lectured on OSS network management and Internet services,
and served as president of the Tacoma Linux User Group. François is a Red Hat
Certified Engineer (RHCE). In his spare time, François enjoys managing enterprise
Cisco networks.
82911ffirs.qxd:Toolbox 10/19/07 12:41 PM Page vii
82911ffirs.qxd:Toolbox 10/19/07 12:41 PM Page viii
Credits
Acquisitions Editor
Jenny Watson
Development Editor
Sara Shlaer
Technical Editor
Thomas Blader
Copy Editor
Michael Koch
Editorial Manager
Mary Beth Wakefield
Production Manager
Tim Tate
Vice President and
Executive Group Publisher
Richard Swadley
Vice President and Executive Publisher
Joseph B. Wikert
Project Coordinator, Cover
Lynsey Osborn
Compositor
Laurie Stewart,
Happenstance Type-O-Rama
Proofreader
Kathryn Duggan
Indexer
Melanie Belkin
Anniversary Logo Design
Richard Pacifico
82911ffirs.qxd:Toolbox 10/19/07 12:41 PM Page ix
Contents at a Glance
Chapter 1: Starting with Fedora Linux . . . . . . . . . . . . . . . . . . . . .1
Chapter 2: Installing Fedora and Adding Software . . . . . . . . . . .13
Chapter 3: Using the Shell . . . . . . . . . . . . . . . . . . . . . . . . . . .33
Chapter 4: Working with Files . . . . . . . . . . . . . . . . . . . . . . . . .51
Chapter 5: Manipulating Text . . . . . . . . . . . . . . . . . . . . . . . . . .71
Chapter 6: Playing with Multimedia . . . . . . . . . . . . . . . . . . . . .89
Chapter 7: Administering File Systems . . . . . . . . . . . . . . . . . .103
Chapter 8: Backups and Removable Media . . . . . . . . . . . . . . .131
Chapter 9: Checking and Managing Running Processes . . . . . .147
Chapter 10: Managing the System . . . . . . . . . . . . . . . . . . . . .165
Chapter 11: Managing Network Connections . . . . . . . . . . . . .187
Chapter 12: Accessing Network Resources . . . . . . . . . . . . . . .209
Chapter 13: Doing Remote System Administration . . . . . . . . .229
Chapter 14: Locking Down Security . . . . . . . . . . . . . . . . . . . .247
Appendix A: Using vi or Vim Editors . . . . . . . . . . . . . . . . . . . .263
Appendix B: Shell Special Characters and Variables . . . . . . . .271
Appendix C: Getting Information from /proc . . . . . . . . . . . . . .275
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .281
82911ffirs.qxd:Toolbox 10/19/07 12:41 PM Page x
Contents
Acknowledgments
xix
Introduction
xxi
Chapter 1: Starting with Fedora Linux
1
About Fedora, Red Hat, and Linux
2
Comparing Fedora to Other Linuxes
3
Finding Fedora Resources
4
Focusing on Linux Commands
5
Finding Commands
6
Command Reference Information in Fedora
8
Summary
11
Chapter 2: Installing Fedora and Adding Software
13
Installing Fedora
13
Preparing to Install
14
Choosing Installation Options
14
Answering Installation Questions
17
Working with Software Packages
19
Using yum Software Repositories
20
Enabling Repositories for yum
21
Using the yum Command
23
Using yum Utilities
26
Managing Software with rpm
26
Using the rpm Command
27
Building RPMs from SRPMs
31
Extracting Files from RPMs
31
Summary
32
Chapter 3: Using the Shell
33
Terminal Windows and Shell Access
33
Using Terminal Windows
33
Using Virtual Terminals
35
82911ftoc.qxd:Toolbox 10/18/07 4:05 PM Page xi
xii
Contents
Using the Shell
35
Using Bash History
36
Using Command Line Completion
37
Redirecting stdin and stdout
37
Using alias
40
Watching Commands
41
Watching Files
41
Acquiring Super User Power
41
Using the su Command
41
Delegating Power with sudo
42
Using Environment Variables
43
Creating Simple Shell Scripts
45
Editing and Running a Script
45
Adding Content to Your Script
45
Summary
49
Chapter 4: Working with Files
51
Understanding File Types
51
Using Regular Files
51
Using Directories
52
Using Symbolic and Hard Links
53
Using Device Files
54
Using Named Pipes and Sockets
54
Setting File/Directory Permissions
55
Changing Permissions with chmod
56
Setting the umask
58
Changing Ownership
58
Traversing the File System
59
Copying Files
60
Changing File Attributes
62
Searching for Files
63
Finding Files with locate
63
Locating Files with find
64
Using Other Commands to Find Files
66
Finding Out More About Files
66
Listing Files
67
Verifying Files
67
Summary
69
82911ftoc.qxd:Toolbox 10/18/07 4:05 PM Page xii
xiii
Contents
Chapter 5: Manipulating Text
71
Matching Text with Regular Expressions
71
Editing Text Files
72
Using the JOE Editor
73
Using the pico and nano Editors
76
Graphical Text Editors
78
Listing, Sorting, and Changing Text
78
Listing Text Files
79
Paging Through Text
80
Paginating Text Files with pr
80
Searching for Text with grep
81
Replacing Text with sed
83
Translating or Removing Characters with tr
84
Checking Differences Between Two Files with diff
85
Using awk and cut to Process Columns
87
Converting Text Files to Different Formats
88
Summary
88
Chapter 6: Playing with Multimedia
89
Working with Audio
89
Playing Music
89
Adjusting Audio Levels
91
Ripping CD Music
92
Encoding Music
93
Streaming Music
95
Converting Audio Files
97
Transforming Images
98
Getting Information about Images
98
Converting Images
99
Converting Images in Batches
100
Summary
102
Chapter 7: Administering File Systems
103
Understanding File System Basics
103
Creating and Managing File Systems
105
Partitioning Hard Disks
105
Working with File System Labels
109
82911ftoc.qxd:Toolbox 10/18/07 4:05 PM Page xiii
xiv
Contents
Formatting a File System
110
Viewing and Changing File System Attributes
111
Creating and Using Swap Partitions
113
Mounting and Unmounting File Systems
114
Mounting File Systems from the fstab File
114
Mounting File Systems with the mount Command
116
Unmounting File Systems with umount
119
Checking File Systems
119
Checking RAID Disks
121
Finding Out About File System Use
123
Logical Volume Manager
124
Creating LVM Volumes
125
Using LVM Volumes
127
Growing the LVM Volume
128
Shrinking an LVM Volume
129
Removing LVM Logical Volumes and Groups
129
Summary
130
Chapter 8: Backups and Removable Media
131
Backing Up Data to Compressed Archives
131
Creating Backup Archives with tar
131
Using Compression Tools
133
Listing, Joining, and Adding Files to tar Archives
136
Deleting Files from tar Archives
137
Backing Up Over Networks
137
Backing Up tar Archives Over ssh
137
Backing Up Files with rsync
139
Backing Up with unison
140
Backing Up to Removable Media
141
Creating Backup Images with mkisofs
142
Burning Backup Images with cdrecord
144
Making and Burning DVDs with growisofs
146
Summary
146
Chapter 9: Checking and Managing Running Processes
147
Listing Active Processes
148
Viewing Active Processes with ps
148
Watching Active Processes with top
153
82911ftoc.qxd:Toolbox 10/18/07 4:05 PM Page xiv
xv
Contents
Finding and Controlling Processes
155
Using pgrep to Find Processes
155
Using fuser to Find Processes
156
Changing Running Processes
157
Summary
163
Chapter 10: Managing the System
165
Monitoring Resources
165
Monitoring Memory Use
166
Monitoring CPU Usage
169
Monitoring Storage Devices
172
Mastering Time
174
Changing Time/Date with Graphical Tools
174
Displaying and Setting Your System Clock
175
Displaying and Setting Your Hardware Clock
176
Using Network Time Protocol to Set Date/Time
177
Trying Other Date/Time Commands
178
Managing the Boot Process
178
Using the GRUB Boot Loader
179
Repairing the initial ramdisk (initrd)
180
Controlling Startup and Run Levels
180
Straight to the Kernel
182
Poking at the Hardware
185
Summary
186
Chapter 11: Managing Network Connections
187
Configuring Networks from the GUI
187
Managing Network Interface Cards
188
Managing Network Connections
191
Starting and Stopping Ethernet Connections
191
Viewing Ethernet Connection Information
193
Using Wireless Connections
194
Using Dial-up Modems
196
Checking Name Resolution
199
Troubleshooting Network Problems
201
Checking Connectivity to a Host
201
Checking Address Resolution Protocol (ARP)
202
82911ftoc.qxd:Toolbox 10/18/07 4:05 PM Page xv
xvi
Contents
Tracing Routes to Hosts
203
Displaying netstat Connections and Statistics
206
Other Useful Network Tools
206
Summary
207
Chapter 12: Accessing Network Resources
209
Running Commands to Browse the Web
209
Transferring Files
211
Downloading Files with wget
211
Transferring Files with cURL
212
Transfering Files with FTP Commands
213
Using SSH Tools to Transfer Files
215
Using Windows File Transfer Tools
216
Sharing Remote Directories
217
Sharing Remote Directories with NFS
217
Sharing Remote Directories with Samba
219
Sharing Remote Directories with SSHFS
222
Chatting with Friends in IRC
223
Using Text-Based E-mail Clients
224
Managing E-mail with mail
224
Managing E-mail with mutt
225
Summary
227
Chapter 13: Doing Remote System Administration
229
Doing Remote Login and Tunneling with SSH
229
Configuring SSH
230
Logging in Remotely with ssh
231
Using screen: A Rich Remote Shell
236
Using a Remote Windows Desktop
239
Connecting to a Windows Desktop with tsclient
240
Connecting to a Windows Desktop with rdesktop
241
Using Remote Linux Desktop and Applications
241
Sharing Desktops Using VNC
242
Setting Up the VNC Server
243
Starting Up the VNC Client
243
Using VNC on Untrusted Networks with SSH
244
Sharing a VNC Desktop with Vino
245
Summary
246
82911ftoc.qxd:Toolbox 10/18/07 4:05 PM Page xvi