Tải bản đầy đủ (.pdf) (339 trang)

Wiley SUSE linux toolbox 1000 plus commands for OpenSUSE and SUSE linux enterprise dec 2007 ISBN 0470082925 pdf

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (3.19 MB, 339 trang )


82928ffirs.qxd:Toolbox

11/1/07

12:31 PM

Page iii

SUSE®Linux®
TO O L B OX
1000+ Commands for openSUSE
and SUSE Linux Enterprise

Christopher Negus
François Caen

Wiley Publishing, Inc.


82928ffirs.qxd:Toolbox

11/1/07

12:31 PM

Page ii


82928ffirs.qxd:Toolbox


11/1/07

12:31 PM

Page i

SUSE®Linux®
TO O L B OX


82928ffirs.qxd:Toolbox

11/1/07

12:31 PM

Page ii


82928ffirs.qxd:Toolbox

11/1/07

12:31 PM

Page iii

SUSE®Linux®
TO O L B OX
1000+ Commands for openSUSE

and SUSE Linux Enterprise

Christopher Negus
François Caen

Wiley Publishing, Inc.


82928ffirs.qxd:Toolbox

11/1/07

12:40 PM

Page iv

SUSE® Linux® Toolbox:
1000+ Commands for openSUSE and SUSE Linux Enterprise
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-08292-8
Manufactured in the United States of America
10 9 8 7 6 5 4 3 2 1
Library of Congress Cataloging-in-Publication Data is available from the publisher.
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 permission 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 />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 professional person should be sought. Neither the publisher nor the author shall be liable for damages arising herefrom. 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.
SUSE and openSUSE are registered trademarks of Novell, 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.


82928ffirs.qxd:Toolbox

11/1/07

12:31 PM


Page v

As always, I dedicate my work on this book to my wife, Sheree.
— Christopher Negus
I dedicate this book to the UnderLUG crew.
— François Caen


82928ffirs.qxd:Toolbox

11/1/07

12:31 PM

Page vi


82928ffirs.qxd:Toolbox

11/1/07

12:31 PM

Page vii

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.


82928ffirs.qxd:Toolbox

11/1/07

12:31 PM

Page viii


82928ffirs.qxd:Toolbox

11/1/07

12:31 PM

Page ix

Credits
Acquisitions Editor


Vice President and Executive Publisher

Jenny Watson

Joseph B. Wikert

Development Editor

Project Coordinator, Cover

Sara Shlaer

Lynsey Osborn

Technical Editor

Compositor

Thomas Blader

Laurie Stewart,
Happenstance Type-O-Rama

Copy Editor
Michael Koch

Proofreader
Kathryn Duggan

Editorial Manager

Mary Beth Wakefield

Indexer
Melanie Belkin

Production Manager
Tim Tate

Anniversary Logo Design
Richard Pacifico

Vice President and
Executive Group Publisher
Richard Swadley


82928ffirs.qxd:Toolbox

11/1/07

12:31 PM

Page x

Contents at a Glance
Chapter 1: Starting with SUSE . . . . . . . . . . . . . . . . . . . . . . . . .1
Chapter 2: Installing openSUSE and Adding Software . . . . . . . .11
Chapter 3: Using the Shell . . . . . . . . . . . . . . . . . . . . . . . . . . .41
Chapter 4: Working with Files . . . . . . . . . . . . . . . . . . . . . . . . .59
Chapter 5: Manipulating Text . . . . . . . . . . . . . . . . . . . . . . . . . .79

Chapter 6: Playing with Multimedia . . . . . . . . . . . . . . . . . . . . .97
Chapter 7: Administering File Systems . . . . . . . . . . . . . . . . . .111
Chapter 8: Backups and Removable Media . . . . . . . . . . . . . . .139
Chapter 9: Checking and Managing Running Processes . . . . . .155
Chapter 10: Managing the System . . . . . . . . . . . . . . . . . . . . .173
Chapter 11: Managing Network Connections . . . . . . . . . . . . .195
Chapter 12: Accessing Network Resources . . . . . . . . . . . . . . .215
Chapter 13: Doing Remote System Administration . . . . . . . . .235
Chapter 14: Locking Down Security . . . . . . . . . . . . . . . . . . . .251
Appendix A: Using vi or Vim Editors . . . . . . . . . . . . . . . . . . . .265
Appendix B: Shell Special Characters and Variables . . . . . . . .273
Appendix C: Getting Information from /proc . . . . . . . . . . . . . .277
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .283


82928ftoc.qxd:Toolbox

11/1/07

12:32 PM

Page xi

Contents
Acknowledgments
Introduction

xix
xxi


Chapter 1: Starting with SUSE

1

About SUSE, Novell, and Linux

2

Comparing SUSE to Other Linux Versions
Finding SUSE Resources

Focusing on Linux Commands
Finding Commands
Command Reference Information in SUSE

Summary

Chapter 2: Installing openSUSE and Adding Software
Installing openSUSE
Preparing to Install
Choosing Installation Options
Answering Installation Questions

Working with Software Packages
Getting Software Packages with YaST
Adding and Updating Software with YaST
Using zypper to Manage Software
Working with zypper Repositories
Searching for Software with zypper
Installing and Removing Software with zypper


Managing Software with RPM
Installing a Package with rpm
Upgrading a Package with rpm
Removing a Package with rpm
Querying Information about RPM Packages
Verifying Installed Packages with rpm
Building RPMs from SRPMs
Extracting Files from RPMs

Summary

2
3

4
5
6

10

11
11
12
12
15

18
19
20

23
24
27
31

33
34
34
35
35
38
39
40

40


82928ftoc.qxd:Toolbox

11/1/07

12:32 PM

Page xii

Contents
Chapter 3: Using the Shell
Terminal Windows and Shell Access
Using Terminal Windows
Using Virtual Terminals


Using the Shell
Using Bash History
Using Command Line Completion
Redirecting stdin and stdout
Using alias
Watching Commands
Watching Files

41
41
43

44
44
45
46
49
50
50

Acquiring Superuser Power

50

Using the su Command
Delegating Power with sudo

50
51


Using Environment Variables
Creating Simple Shell Scripts

52
54

Editing and Running a Script
Adding Content to Your Script

Summary

Chapter 4: Working with Files
Understanding File Types
Using
Using
Using
Using
Using

54
54

58

59
59

Regular Files
Directories

Symbolic and Hard Links
Device Files
Named Pipes and Sockets

59
61
61
62
63

Setting File and Directory Permissions

63

Changing Permissions with chmod
Setting the umask
Changing Ownership

xii

41

64
66
66

Traversing the File System
Copying Files
Changing File Attributes
Searching for Files


67
68
70
71

Finding Files with locate
Locating Files with find

72
72


82928ftoc.qxd:Toolbox

11/1/07

12:32 PM

Page xiii

Contents
Using Other Commands to Find Files

Finding Out More About Files
Listing Files
Verifying Files

Summary


Chapter 5: Manipulating Text
Matching Text with Regular Expressions
Editing Text Files
Using the JOE Editor
Using the Pico and nano Editors
Graphical Text Editors

Listing, Sorting, and Changing Text
Listing Text Files
Paging Through Text
Paginating Text Files with pr
Searching for Text with grep
Replacing Text with sed
Translating or Removing Characters with tr
Checking Differences Between Two Files with diff
Using awk and cut to Process Columns
Converting Text Files to Different Formats

Summary

Chapter 6: Playing with Multimedia
Working with Audio
Playing Music
Adjusting Audio Levels
Ripping CD Music
Encoding Music
Streaming Music
Converting Audio Files

Transforming Images

Getting Information about Images
Converting Images
Converting Images in Batches

Summary

75

75
75
76

78

79
79
80
81
84
86

86
87
88
88
89
91
92
93
95

96

96

97
97
97
99
100
101
103
105

106
106
107
109

109

xiii


82928ftoc.qxd:Toolbox

11/1/07

12:32 PM

Page xiv


Contents
Chapter 7: Administering File Systems

111

Understanding File System Basics
Creating and Managing File Systems

111
113

Partitioning Hard Disks
Working with File System Labels
Formatting a File System
Viewing and Changing File System Attributes
Creating and Using Swap Partitions

Mounting and Unmounting File Systems
Mounting File Systems from the fstab File
Mounting File Systems with the mount Command
Unmounting File Systems with umount

Checking File Systems
Checking RAID Disks
Finding Out About File System Use
Logical Volume Manager
Creating LVM Volumes
Using LVM Volumes
Growing the LVM Volume

Shrinking an LVM Volume
Removing LVM Logical Volumes and Groups

Summary

113
117
118
119
121

122
122
124
127

127
129
131
132
133
135
136
137
137

138

Chapter 8: Backups and Removable Media


139

Backing Up Data to Compressed Archives

139

Creating Backup Archives with tar
Using Compression Tools
Listing, Joining, and Adding Files to tar Archives
Deleting Files from tar Archives

Backing Up Over Networks
Backing Up tar Archives Over ssh
Backing Up Files with rsync
Backing Up with unison
Backing Up to Removable Media
Creating Backup Images with mkisofs
Burning Backup Images with cdrecord
Making and Burning DVDs with growisofs

Summary

xiv

139
141
144
145

145

145
147
148
149
150
152
154

154


82928ftoc.qxd:Toolbox

11/1/07

12:32 PM

Page xv

Contents
Chapter 9: Checking and Managing Running Processes
Listing Active Processes

155
156

Viewing Active Processes with ps
Watching Active Processes with top

156

162

Finding and Controlling Processes

163

Using pgrep to Find Processes
Using fuser to Find Processes
Changing Running Processes

Summary

Chapter 10: Managing the System
Monitoring Resources
Monitoring Memory Use
Monitoring CPU Usage
Monitoring Storage Devices

Mastering Time
Changing Time/Date with Graphical Tools
Displaying and Setting Your System Clock
Displaying and Setting Your Hardware Clock
Using Network Time Protocol to Set Date/Time
Trying Other Date/Time Commands

Managing the Boot Process

163
164
165


171

173
173
174
177
179

181
182
182
184
184
185

186

Using the GRUB Boot Loader
Repairing the initial ramdisk (initrd)

186
187

Controlling Startup and Run Levels
Straight to the Kernel
Poking at the Hardware
Summary

188

190
193
194

Chapter 11: Managing Network Connections
Configuring Networks from the GUI
Managing Network Interface Cards
Managing Network Connections
Starting and Stopping Ethernet Connections
Viewing Ethernet Connection Information

Using Wireless Connections
Using Dial-up Modems

195
195
196
198
199
200

201
203

xv


82928ftoc.qxd:Toolbox

11/1/07


12:32 PM

Page xvi

Contents
Checking Name Resolution
Troubleshooting Network Problems
Checking Connectivity to a Host
Checking Address Resolution Protocol (ARP)
Tracing Routes to Hosts
Displaying netstat Connections and Statistics
Other Useful Network Tools

Summary

Chapter 12: Accessing Network Resources
Running Commands to Browse the Web
Transferring Files
Downloading Files with wget
Transferring Files with cURL
Transfering Files with FTP Commands
Using SSH Tools to Transfer Files
Using Windows File Transfer Tools

Sharing Remote Directories
Sharing Remote Directories with NFS
Sharing Remote Directories with Samba
Sharing Remote Directories with SSHFS


Chatting with Friends in IRC
Using Text-Based E-mail Clients
Managing E-mail with mail
Managing E-mail with mutt

Summary

Chapter 13: Doing Remote System Administration
Doing Remote Login and Tunneling with SSH
Configuring SSH
Logging in Remotely with ssh

Using screen: A Rich Remote Shell
Using a Remote Windows Desktop
Connecting to a Windows Desktop with tsclient
Connecting to a Windows Desktop with rdesktop

Using Remote Linux Desktop and Applications
Sharing Desktops Using VNC
Setting Up the VNC Server

xvi

206
208
208
209
210
212
213


214

215
215
216
216
218
219
221
222

223
223
225
229

229
231
231
232

234

235
235
236
237

242

245
246
247

247
248
249


82928ftoc.qxd:Toolbox

11/1/07

12:32 PM

Page xvii

Contents
Starting Up the VNC Client
Using VNC on Untrusted Networks with SSH

Summary

Chapter 14: Locking Down Security

249
250

250


251

Working with Users and Groups

251

Managing Users the GUI Way
Adding User Accounts
Modifying User Accounts
Deleting User Accounts
Managing Passwords
Adding Groups

252
252
254
254
255
257

Checking on Users
Configuring the Built-In Firewall
Working with System Logs
Using Advanced Security Features
Summary

257
259
262
263

264

Appendix A: Using vi or Vim Editors

265

Starting and Quitting the vi Editor
Moving Around in vi
Changing and Deleting Text in vi
Using Miscellaneous Commands
Modifying Commands with Numbers
Using Ex Commands
Working in Visual Mode

265
267
268
269
270
271
272

Appendix B: Shell Special Characters and Variables
Using Special Shell Characters
Using Shell Variables

Appendix C: Getting Information from /proc
Viewing /proc information
Changing /proc information
Index


273
273
274

277
277
281
283

xvii


82928flast.qxd:Toolbox

11/1/07

12:32 PM

Page xviii


82928flast.qxd:Toolbox

11/1/07

12:32 PM

Page xix


Acknowledgments
I would like to acknowledge the free and open source software community for making
openSUSE, SUSE Linux Enterprise, and other Linux distributions possible.
Special thanks to François Caen for giving up most of his free time over the past
year, while juggling his existing professional obligations, to co-author the book with
me. Thomas Blader went far beyond his technical editor title, contributing most of
Chapters 1 and 2, and many other enhancements to the book.
At Wiley, I’d like to thank Jenny Watson for sticking with us through the development
of the book. And, last but not least, thanks to Sara Shlaer for keeping us on track with
schedules and supplying the never-ending to-do lists we needed to accomplish to get
this book published.
— Christopher Negus

I would like to thank Chris Negus for giving me the opportunity to co-author this book
with him. We had wanted to write together for the last couple of years, and this Toolbox
series was the perfect fit for our collaboration.
I couldn’t have worked on this book without the unrelenting support from my wife,
Tonya. Thank you for emptying the dishwasher all these times even though we both
know it’s my job.
Thanks to Thomas Blader for his ultra-detailed tech editing and for his contribution on
the first two chapters. Thanks to Sara Shlaer for her guidance throughout the authoring
process, and to Jenny Watson for being the most patient cat-herder out there.
Finally, I would like to express my gratitude towards the communities that make
openSUSE, other Linuxes, and all Free Software possible.
— François Caen


82928flast.qxd:Toolbox

11/1/07


12:32 PM

Page xx


82928flast.qxd:Toolbox

11/1/07

12:32 PM

Page xxi

Introduction
After you’ve had some experience with Linux, you don’t need someone telling you
to click the Help button for help or drag a file to the Trash icon to delete it. What you
need is a reference book that shows you powerful commands and options that let
you take hold of your Linux system, as well as the processes, users, storage media,
network resources, and system services associated with it.
SUSE Linux Toolbox provides you with more than 1000 specific command lines to help
you become a Linux power user. Whether you are a systems administrator or desktop
user, the book will show you commands to create file systems, troubleshoot networks,
lock down security, and dig out almost anything you care to know about your Linux
system.
This book’s focus for your Linux command-line journey is openSUSE, the communitybased Linux distribution sponsored by Novell, Inc. and SUSE Linux Enterprise. Tapping
into the skills needed to run those systems can help you to work with your own Linux
systems and to learn what you need as a Linux professional.

Novell’s Bold Move with SUSE

Novell, Inc., which develops SUSE Linux systems, shook the free and open source software world in 2006 when it entered into a cooperative agreement with Microsoft. That
agreement promised to protect each of the two companies’ customers from patentrelated lawsuits that could arise from the other company’s patent portfolios, while
threatening to set a precedent for a Microsoft tax on thousands of other installed Linux
systems in existence today.
The agreement also brought with it the probability that thousands of SUSE installations
would make their way into locations that were once exclusively Microsoft shops. Linux
systems that were once touted as evil, broken, incompatible, “just a toy,” or stolen from
honest commercial software developers is, in one wave of the hand, just fine for the
Microsoft faithful to use . . . as long as they choose Novell’s SUSE Linux systems.
Despite the fact that Microsoft has not contributed code to Linux, the alliance between
Novell and Microsoft has made only SUSE Linux customers safe from Microsoft’s
lawsuit threats (and only for a limited time). This has angered many free and open
source software developers to the point where they will no longer have anything to
do with SUSE.
With this book, however, we are taking a different approach.


82928flast.qxd:Toolbox

11/1/07

12:32 PM

Page xxii

Introduction
The authors of this book will not try to break your operating system, charge you a tax
for the work we have put into Linux, or even persuade you to not use SUSE. That’s not
how we have ever done business and is not how we are going to start doing it now.
Instead, we will teach you Linux. For today, we will help you keep your job and even

thrive in your new Linux environment. If some day SUSE becomes less relevant, yet
you still need the power and flexibility that the free and open source software movement affords (which is today reflected best in Linux), you will have the skills you need
to move forward.
Make no mistake about it. This is a Linux book for professionals or serious hobbyists.
Linux is a powerful, network-enabled, multi-user, multitasking operating system. It’s
built from the ground up for security and interoperability. Microsoft’s alliance has conceded that many of its customers need Linux. It’s time for you to see how it works as a
power user.
In this book, what you will get are the commands you need to master your SUSE
Linux systems. Most of those skills will translate to other Linux systems as well, so
you will have the freedom to use those skills with Ubuntu, Fedora, Slackware, Gentoo,
Red Hat Enterprise Linux, or any other Linux you choose. So, even if your employer
or software vendor boxes you in contractually to SUSE, it will not box in your mind.
Your teachers in this endeavor are not a couple of latecomers to this newfound
Microsoft/Novell Linux religion. Our credentials reflect more than 40 years combined experience with Linux systems and the Unix systems on which they were
based. You will learn from those who have used Linux for years and are willing
to bring you into it, for whatever reason you have been drawn to Linux.

Who Should Read This Book
This book is for anyone who wants to access the power of a Linux system as a systems
administrator or user. You may be a Linux enthusiast, a Linux professional, or possibly
a computer professional who is increasingly finding the Windows systems in your data
center supplanted by Linux boxes.
The bottom line is that you want to find quick and efficient ways of getting openSUSE
and SUSE Linux Enterprise systems working at peak performance. Those systems may
be a few desktop systems at work, a file and print server at your school, or a home Web
server that you’re doing just for fun.
In the best case, you should already have some experience with Linux. However, if you
are a computer professional with skills managing other types of operating systems, such
as Windows, you should be able to easily adapt your knowledge to be able to use the
specific commands we cover in the book.


xxii


×