30
BSD UNIX ® TOOLBOX 1000+ Commands for FreeBSD ® , OpenBSD, and NetBSD ® Power Users Christopher Negus François Caen

Christopher Negus François Caendownload.e-bookshelf.de/download/0000/5719/47/L-G... · About the Authors Christopher Negus is the author of the best-selling Fedora and Red Hat Linux

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Christopher Negus François Caendownload.e-bookshelf.de/download/0000/5719/47/L-G... · About the Authors Christopher Negus is the author of the best-selling Fedora and Red Hat Linux

BSD UNIX®TOOLBOX

1000+ Commands for FreeBSD®, OpenBSD, and NetBSD®Power Users

Christopher NegusFrançois Caen

76034ffirs.qxd:Toolbox 4/2/08 12:50 PM Page iii

Page 2: Christopher Negus François Caendownload.e-bookshelf.de/download/0000/5719/47/L-G... · About the Authors Christopher Negus is the author of the best-selling Fedora and Red Hat Linux

76034ffirs.qxd:Toolbox 4/2/08 12:50 PM Page ii

Page 3: Christopher Negus François Caendownload.e-bookshelf.de/download/0000/5719/47/L-G... · About the Authors Christopher Negus is the author of the best-selling Fedora and Red Hat Linux

BSD UNIX®TOOLBOX

76034ffirs.qxd:Toolbox 4/2/08 12:50 PM Page i

Page 4: Christopher Negus François Caendownload.e-bookshelf.de/download/0000/5719/47/L-G... · About the Authors Christopher Negus is the author of the best-selling Fedora and Red Hat Linux

76034ffirs.qxd:Toolbox 4/2/08 12:50 PM Page ii

Page 5: Christopher Negus François Caendownload.e-bookshelf.de/download/0000/5719/47/L-G... · About the Authors Christopher Negus is the author of the best-selling Fedora and Red Hat Linux

BSD UNIX®TOOLBOX

1000+ Commands for FreeBSD®, OpenBSD, and NetBSD®Power Users

Christopher NegusFrançois Caen

76034ffirs.qxd:Toolbox 4/2/08 12:50 PM Page iii

Page 6: Christopher Negus François Caendownload.e-bookshelf.de/download/0000/5719/47/L-G... · About the Authors Christopher Negus is the author of the best-selling Fedora and Red Hat Linux

BSD UNIX® Toolbox: 1000+ Commands for FreeBSD®, OpenBSD, and NetBSD® Power UsersPublished byWiley Publishing, Inc.10475 Crosspoint BoulevardIndianapolis, IN 46256www.wiley.com

Copyright © 2008 by Wiley Publishing, Inc., Indianapolis, Indiana

Published simultaneously in Canada

ISBN: 978-0-470-37603-4

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 byany means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted underSections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of thePublisher, 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 warrantieswith 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 orextended by sales or promotional materials. The advice and strategies contained herein may not be suitable forevery 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 offurther information does not mean that the author or the publisher endorses the information the organization orWebsite may provide or recommendations it may make. Further, readers should be aware that Internet Websiteslisted 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 Departmentwithin the United States at (800) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002.

Trademarks: Wiley, the Wiley logo, and related trade dress are trademarks or registered trademarks of JohnWiley & Sons, Inc. and/or its affiliates, in the United States and other countries, and may not be used withoutwritten permission. UNIX is a registered trademark of X/Open Company. FreeBSD is a registered trademark of FreeBSD Foundation. NetBSD is a registered trademark of NetBSD Foundation. All other trademarks are theproperty of their respective owners. Wiley Publishing, Inc. is not associated with any product or vendor men-tioned in this book.

Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not beavailable in electronic books.

76034ffirs.qxd:Toolbox 4/2/08 12:50 PM Page iv

Page 7: Christopher Negus François Caendownload.e-bookshelf.de/download/0000/5719/47/L-G... · About the Authors Christopher Negus is the author of the best-selling Fedora and Red Hat Linux

As always, I dedicate my work on this book to my wife, Sheree.

— Christopher Negus

To my wife, Tonya, for supporting me in all my endeavors.

— François Caen

76034ffirs.qxd:Toolbox 4/2/08 12:50 PM Page v

Page 8: Christopher Negus François Caendownload.e-bookshelf.de/download/0000/5719/47/L-G... · About the Authors Christopher Negus is the author of the best-selling Fedora and Red Hat Linux

76034ffirs.qxd:Toolbox 4/2/08 12:50 PM Page vi

Page 9: Christopher Negus François Caendownload.e-bookshelf.de/download/0000/5719/47/L-G... · About the Authors Christopher Negus is the author of the best-selling Fedora and Red Hat Linux

About the AuthorsChristopher Negus is the author of the best-selling Fedora and Red Hat Linux Bibles,Linux Toys, Linux Troubleshooting Bible, and Linux Bible 2008 Edition. He is a member ofthe Madison Linux Users Group. Before becoming a full-time writer, Chris served foreight years on development teams for the UNIX operating system at AT&T, where UNIXwas created and developed. He also worked with Novell on Linux development andCaldera Linux.

François Caen, through his company Turbosphere LLC, hosts and manages businessapplication infrastructures, with 95 percent running on Linux systems. As an opensource advocate, he has lectured on OSS network management and Internet servicesand served as president of the Tacoma Linux Users Group. François is a Red HatCertified Engineer (RHCE). In his spare time, he enjoys managing enterprise Cisconetworks.

About the Technical EditorThomas Blader first began dabbling in Linus/UNIX in 1993 with Yggdrasil Linuxand BSD. Since 1997, he has worked for the same company as a Solaris/Linux admin-istrator. He has recently become involved with network security. He also does UNIX-related consulting and software development as well as book writing and editing.

76034ffirs.qxd:Toolbox 4/2/08 12:50 PM Page vii

Page 10: Christopher Negus François Caendownload.e-bookshelf.de/download/0000/5719/47/L-G... · About the Authors Christopher Negus is the author of the best-selling Fedora and Red Hat Linux

76034ffirs.qxd:Toolbox 4/2/08 12:50 PM Page viii

Page 11: Christopher Negus François Caendownload.e-bookshelf.de/download/0000/5719/47/L-G... · About the Authors Christopher Negus is the author of the best-selling Fedora and Red Hat Linux

CreditsAcquisitions EditorJenny Watson

Development EditorWilliam Bridges

Technical EditorThomas Blader

Production EditorDaniel Scribner

Copy EditorMichael Koch

Editorial ManagerMary Beth Wakefield

Production ManagerTim Tate

Vice President and Executive Group PublisherRichard Swadley

Vice President and Executive PublisherJoseph B. Wikert

Project Coordinator, CoverLynsey Osborn

CompositorLaurie Stewart, Happenstance Type-O-Rama

ProofreaderDavid Parise, Word One

IndexerMelanie Belkin

76034ffirs.qxd:Toolbox 4/2/08 12:50 PM Page ix

Page 12: Christopher Negus François Caendownload.e-bookshelf.de/download/0000/5719/47/L-G... · About the Authors Christopher Negus is the author of the best-selling Fedora and Red Hat Linux

Contents at a GlanceChapter 1: Starting with BSD Systems . . . . . . . . . . . . . . . . . . . .1Chapter 2: Installing FreeBSD and Adding Software . . . . . . . . . .13Chapter 3: Using the Shell . . . . . . . . . . . . . . . . . . . . . . . . . . .33Chapter 4: Working with Files . . . . . . . . . . . . . . . . . . . . . . . . .51Chapter 5: Manipulating Text . . . . . . . . . . . . . . . . . . . . . . . . . .71Chapter 6: Playing with Multimedia . . . . . . . . . . . . . . . . . . . . .89Chapter 7: Administering File Systems . . . . . . . . . . . . . . . . . .103Chapter 8: Backups and Removable Media . . . . . . . . . . . . . . .127Chapter 9: Checking and Managing Running Processes . . . . . .143Chapter 10: Managing the System . . . . . . . . . . . . . . . . . . . . .161Chapter 11: Managing Network Connections . . . . . . . . . . . . .185Chapter 12: Accessing Network Resources . . . . . . . . . . . . . . .205Chapter 13: Doing Remote System Administration . . . . . . . . .225Chapter 14: Locking Down Security . . . . . . . . . . . . . . . . . . . .243Appendix A: Using vi or Vim Editors . . . . . . . . . . . . . . . . . . . .263Appendix B: Shell Special Characters and Variables . . . . . . . .271Appendix C: Personal Configuration Files . . . . . . . . . . . . . . . .277Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .281

76034ffirs.qxd:Toolbox 4/2/08 12:50 PM Page x

Page 13: Christopher Negus François Caendownload.e-bookshelf.de/download/0000/5719/47/L-G... · About the Authors Christopher Negus is the author of the best-selling Fedora and Red Hat Linux

Contents

Acknowledgments xixIntroduction xxi

Chapter 1: Starting with BSD Systems 1

About FreeBSD, NetBSD, and OpenBSD 2Finding BSD Resources 4

Focusing on BSD Commands 6Finding Commands 7Command Reference Information in BSD 8

Summary 11

Chapter 2: Installing FreeBSD and Adding Software 13

Before Installing FreeBSD 13Installing FreeBSD 14

Booting the Install Disc 14Starting the Install Process 15

Adding, Deleting, and Managing Software 19Finding Software 19Installing Software Packages (binary) 21Removing Software Packages (binary) 22Installing Software Using Ports (source code) 23Getting and Installing Applications with Ports 25

Checking Packages and Ports 28Checking Installed Packages Against Ports 28Upgrading Ports 28Auditing Installed Packages 29Cleaning Up the Ports Collection 30

Summary 31

Chapter 3: Using the Shell 33

Terminal Windows and Shell Access 33Using Terminal Windows 33Using Virtual Terminals 35

76034ftoc.qxd:Toolbox 4/2/08 1:04 PM Page xi

Page 14: Christopher Negus François Caendownload.e-bookshelf.de/download/0000/5719/47/L-G... · About the Authors Christopher Negus is the author of the best-selling Fedora and Red Hat Linux

xii

Contents

Using the Shell 36Using Bash History 36Using Command Line Completion 38Redirecting stdin and stdout 38Using aliases 41Tailing Files 41

Acquiring Super-User Power 41Using the su Command 42Delegating Power with sudo 43

Using Environment Variables 44Creating Simple Shell Scripts 45

Editing and Running a Script 45Adding Content to Your Script 46

Summary 50

Chapter 4: Working with Files 51

Understanding File Types 51Using Regular Files 51Using Directories 52Using Symbolic and Hard Links 53Using Device Files 54Using Named Pipes and Sockets 54

Setting File and Directory Permissions 55Changing Permissions with chmod 56Setting the umask 58Changing Ownership 58

Traversing the File System 59Copying Files 60Changing File Attributes 62Searching for Files 63

Generating the locate Database 63Finding Files with locate 64Locating Files with find 65Using Other Commands to Find Files 67

Finding Out More About Files 67Listing Files 67Verifying Files 68

Summary 69

76034ftoc.qxd:Toolbox 4/2/08 1:04 PM Page xii

Page 15: Christopher Negus François Caendownload.e-bookshelf.de/download/0000/5719/47/L-G... · About the Authors Christopher Negus is the author of the best-selling Fedora and Red Hat Linux

xiii

Contents

Chapter 5: Manipulating Text 71

Matching Text with Regular Expressions 71Editing Text Files 72

Using the JOE Editor 73Using the Pico and Nano Editors 76Graphical Text Editors 78

Listing, Sorting, and Changing Text 78Listing Text Files 78Paging Through Text 79Paginating Text Files with pr 80Searching for Text with grep 81Replacing Text with sed 83Translate or Remove Characters with tr 84Checking Differences Between Two Files with diff 85Using awk and cut to Process Columns 87Converting Text Files to Different Formats 88

Summary 88

Chapter 6: Playing with Multimedia 89

Working with Audio 89Starting with Audio 89Playing Music 90Adjusting Audio Levels 91Ripping CD Music 92Encoding Music 93Converting Audio Files 96

Transforming Images 97Getting Information about Images 97Converting Images 98Converting Images in Batches 100

Summary 101

Chapter 7: Administering File Systems 103

Understanding File System Basics 103Setting Up the Disk Initially 104Checking Your Disk Setup 104Understanding File System Types 106

76034ftoc.qxd:Toolbox 4/2/08 1:04 PM Page xiii

Page 16: Christopher Negus François Caendownload.e-bookshelf.de/download/0000/5719/47/L-G... · About the Authors Christopher Negus is the author of the best-selling Fedora and Red Hat Linux

xiv

Contents

Creating and Managing File Systems 107Slicing and Partitioning Hard Disks 107Working with Linux-Compatible File Systems 114Creating a Memory Disk File System 116Creating and Using Swap Partitions 117

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

Checking File Systems 122Finding Out About File System Use 124Summary 126

Chapter 8: Backups and Removable Media 127

Backing Up Data to Compressed Archives 127Creating Backup Archives with tar 127Using Compression Tools 129Listing, Joining, and Adding Files to tar Archives 132

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

Summary 142

Chapter 9: Checking and Managing Running Processes 143

Listing Active Processes 144Viewing Active Processes with ps 144Watching Active Processes with top 150

Finding and Controlling Processes 151Using pgrep to Find Processes 152Using fuser to Find Processes 152

Summary 159

76034ftoc.qxd:Toolbox 4/2/08 1:04 PM Page xiv

Page 17: Christopher Negus François Caendownload.e-bookshelf.de/download/0000/5719/47/L-G... · About the Authors Christopher Negus is the author of the best-selling Fedora and Red Hat Linux

xv

Contents

Chapter 10: Managing the System 161

Monitoring Resources 161Monitoring Memory Use 162Monitoring CPU Usage 164Monitoring Storage Devices 166

Mastering Time 168Changing Time Zone 169Displaying and Setting Your Time and Date 169Using Network Time Protocol to Set Date/Time 170Checking Uptime 172

Managing the Boot Process 172Using the boot0 Boot Loader 173Using bsdlabel to Check Out Partitions 176Changing to the GRUB boot loader 176

Controlling System Services 178Starting and Stopping Your System 179Straight to the Kernel 179Poking at the Hardware 182Summary 183

Chapter 11: Managing Network Connections 185

Configuring Network Interfaces Using sysinstall 185Managing Network Interface Cards 186Managing Network Connections 190

Starting and Stopping Ethernet Connections 190Starting and Stopping Network Services 191

Using Wireless Connections 192Getting Wireless Driver 192Configuring Wireless Interfaces 193

Checking Name Resolution 194Troubleshooting Network Problems 196

Checking Connectivity to a Host 196Checking Address Resolution Protocol (ARP) 197Tracing Routes to Hosts 198Displaying netstat Connections and Statistics 200Other Useful Network Tools 202

Summary 203

76034ftoc.qxd:Toolbox 4/2/08 1:04 PM Page xv

Page 18: Christopher Negus François Caendownload.e-bookshelf.de/download/0000/5719/47/L-G... · About the Authors Christopher Negus is the author of the best-selling Fedora and Red Hat Linux

xvi

Contents

Chapter 12: Accessing Network Resources 205

Running Commands to Browse the Web 205Transferring Files 207

Downloading Files with wget 207Transferring Files with cURL 208Transferring Files with FTP Commands 209Using SSH Tools to Transfer Files 211Using Windows File Transfer Tools 213

Sharing Remote Directories 213Sharing Remote Directories with NFS 213Sharing Remote Directories with Samba 215Sharing Remote Directories with SSHFS 218

Chatting with Friends in IRC 219Using Text-Based e-mail Clients 220

Managing e-mail with mail 221Managing e-mail with mutt 222

Summary 223

Chapter 13: Doing Remote System Administration 225

Doing Remote Login and Tunneling with SSH 225Configuring SSH 227Logging in Remotely with ssh 228

Using screen: A Rich Remote Shell 233Using a Remote Windows Desktop 236

Connecting to a Windows Desktop with tsclient 236Connecting to a Windows Desktop with rdesktop 237

Using Remote BSD Desktop and Applications 238Sharing Desktops Using VNC 239

Setting Up the VNC Server 239Starting Up the VNC Client 240Using VNC on Untrusted Networks with SSH 241Sharing a VNC Desktop with Vino 241

Summary 242

Chapter 14: Locking Down Security 243

Working with Users and Groups 244Managing Users the GUI Way 244Adding User Accounts 244

76034ftoc.qxd:Toolbox 4/2/08 1:04 PM Page xvi

Page 19: Christopher Negus François Caendownload.e-bookshelf.de/download/0000/5719/47/L-G... · About the Authors Christopher Negus is the author of the best-selling Fedora and Red Hat Linux

xvii

Contents

Adding Batches of Users 245Setting User Account Defaults 247Using Options When Adding Users 248Using Login Classes 249Modifying User Accounts 250Deleting User Accounts 251Managing Passwords 252Adding Groups 252

Checking on Users 253Securing Network Services 255Configuring the Built-In Firewall 258Working with System Logs 261Using Advanced Security Features 261Summary 262

Appendix A: Using vi or Vim Editors 263

Starting and Quitting the vi Editor 264Moving Around in vi 265Changing and Deleting Text in vi 266Using Miscellaneous Commands 268Modifying Commands with Numbers 268Using Ex Commands 269Working in Visual Mode 270Summary 270

Appendix B: Shell Special Characters and Variables 271

Using Special Shell Characters 271Using Shell Variables 272

Appendix C: Personal Configuration Files 277

Index 281

76034ftoc.qxd:Toolbox 4/2/08 1:04 PM Page xvii

Page 20: Christopher Negus François Caendownload.e-bookshelf.de/download/0000/5719/47/L-G... · About the Authors Christopher Negus is the author of the best-selling Fedora and Red Hat Linux

76034flast.qxd:Toolbox 4/2/08 1:06 PM Page xviii

Page 21: Christopher Negus François Caendownload.e-bookshelf.de/download/0000/5719/47/L-G... · About the Authors Christopher Negus is the author of the best-selling Fedora and Red Hat Linux

Acknowledgments

I would like to acknowledge the FreeBSD, OpenBSD, and NetBSD development com-munities, who have continued the noble tradition begun by the Berkeley SoftwareDistribution decades ago. Their efforts have led to some of the most secure and stablecomputer operating systems in or out of the free and open source software world.

Special thanks to François Caen for giving up most of his free time over the past yearas we developed and wrote the books in our Toolbox series. Thomas Blader did hisusual excellent job tech editing this book. At Wiley, I’d like to thank Jenny Watson forsticking with us through the development of the book. Special thanks to Bill Bridges,who kept us on track during a challenging development schedule.

— Christopher Negus

I would like to thank Chris Negus for giving me the opportunity to co-author this bookwith him. We had wanted to write together for the last couple of years, and this Toolboxseries 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 those times even though we bothknow it’s my job.

Thanks to Thomas Blader for his detailed tech editing. Having done some tech editing inthe past, I know what a tough job it can be. Thanks to Sara Shlaer and Jenny Watson atWiley for being the most patient cat-herders out there. Special thanks to Wayne Tuckerand Jesse Keating for all the knowledge they’ve shared with me during and before thisproject.

— François Caen

76034flast.qxd:Toolbox 4/2/08 1:06 PM Page xix

Page 22: Christopher Negus François Caendownload.e-bookshelf.de/download/0000/5719/47/L-G... · About the Authors Christopher Negus is the author of the best-selling Fedora and Red Hat Linux

76034flast.qxd:Toolbox 4/2/08 1:06 PM Page xx

Page 23: Christopher Negus François Caendownload.e-bookshelf.de/download/0000/5719/47/L-G... · About the Authors Christopher Negus is the author of the best-selling Fedora and Red Hat Linux

Introduction

BSD UNIX Toolbox provides you with more than 1,000 specific command lines to helpyou become a BSD power user. Whether you are a systems administrator or desktopuser, 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 BSDsystem.

This book’s focus for your BSD command line journey is FreeBSD, one of the mostpopular BSD derivatives in the world. Tapping into the skills needed to run thosesystems can help you to work with your own BSD systems and to learn what youneed as a BSD professional.

Who Should Read This BookThis book is for anyone who wants to access the power of a BSD system as a systemsadministrator or user. You may be a free and open source software (FOSS) enthusiast,a BSD professional, or possibly a computer professional who is increasingly findingthe Windows systems in your data center supplanted by BSD and Linux boxes.

The bottom line is that you want to find quick and efficient ways of getting FreeBSD,NetBSD, and OpenBSD systems working at peak performance. Those systems may bea few desktop systems at work, a file and print server at your school, or a home webserver that you’re doing just for fun.

In the best case, you should already have some experience with BSD, Linux or otherUNIX-like systems. However, if you are a computer professional with skills manag-ing other types of operating systems, such as Windows, you should be able to easilyadapt your knowledge to be able to use the specific commands we cover in the book.

What This Book CoversThis is not a beginner’s BSD UNIX book. Before you jump in, it would be best if youhave a basic working knowledge of what BSD and other UNIX systems are, how theshell works, and what processes, file systems, and network interfaces are. The bookwill then supplement that knowledge with information you need to do the followingactivities:

❑ Get software — FreeBSD offers both binary software packages and source packagesin the ports database that can be used to download, build, and install software from

76034flast.qxd:Toolbox 4/2/08 1:06 PM Page xxi

Page 24: Christopher Negus François Caendownload.e-bookshelf.de/download/0000/5719/47/L-G... · About the Authors Christopher Negus is the author of the best-selling Fedora and Red Hat Linux

Introduction

xxii

source code. With tools such as pkg_info, pkg_add, and pkg_delete, you’ll learnthe best ways to find, download, install, and otherwise manage software from thecommand line.

❑ Access applications — Find what’s available from the FreeBSD distribution, thenselect and install the ones you want using the sysinstall utility.

❑ Use the shell — Find neat techniques and tips for using the shell.

❑ Play with multimedia — Play and work with multimedia content from your com-puter. You can also modify audio and image files, and then convert the content ofthose files to different formats.

❑ Work with files — Use, manipulate, convert, and secure a wide range of file typesin BSD systems.

❑ Administer file systems — Access, format, partition, and monitor your file stor-age hardware (hard disks, CD/DVD drives, floppy disks, USB flash drives, andso on). Then create, format, and check the file systems that exist on those hard-ware devices.

❑ Back up and restore data — Use simple commands to gather, archive, and com-press your files into efficient backup archives. Then store those archives locally or on remote computers.

❑ Work with processes — List running processes in a variety of ways, such as byCPU use, processor use, or process ID. Then change running processes to havethem run in the background or foreground. Send signals to processes to havethem re-read configuration files, stop and resume processing, or stop completely(abort).

❑ Manage the system — Run commands to check system resources, such as memoryusage, boot loaders, and kernel modules.

❑ Monitor networks — Bring wired, wireless, and dial-up network connections upand down. Check routing, DNS, and host information. Keep an eye on networktraffic.

❑ Get network resources — Connect to BSD and Windows remote file systems usingFTP, NFS, and Samba facilities. Use shell-based commands to browse the Web.

❑ Do remote administration — Access and administer other computers using remotelogin (ssh, telnet, and so on), and screen. Learn about remote administration inter-faces, such as SWAT and CUPS.

❑ Lock down security — Set up firewalls and system logging to secure your BSDsystems.

❑ Get reference information — Use the appendixes at the end of this book to getmore information about the shell (such as metacharacters and shell variables) andpersonal configuration files.

76034flast.qxd:Toolbox 4/2/08 1:06 PM Page xxii

Page 25: Christopher Negus François Caendownload.e-bookshelf.de/download/0000/5719/47/L-G... · About the Authors Christopher Negus is the author of the best-selling Fedora and Red Hat Linux

Introduction

xxiii

Hopefully, if we have done it right, it will be easier to use this book than to Google forthe command lines or GUI tools you need.

After you have mastered many of the features described in this book, you’ll have gainedthe following advantages:

❑ Hundreds of commands — By compressing a lot of information into a small space,you will have access to hundreds of useful commands, in over 1,000 command lines,in a handy form to carry with you.

❑ Critical BSD information — This book lists connections to the most critical infor-mation on the Web for succeeding with BSD systems in general and FreeBSD inparticular.

❑ Transferable knowledge — Most of the same commands and options you use inBSD systems will work exactly the same way on other UNIX-like systems. DifferentUNIX systems, on the other hand, offer different graphical administration tools.And even within a particular distribution, graphical tools change more often thancommands do.

❑ Quick problem solving — By the time others have started up a desktop andlaunched a graphical administration tool, you will have already run a half dozencommands and solved the problem.

❑ Enduring value — Many of the commands described in this book were used inearly UNIX systems. So you are gaining tools that reflect the experience of thou-sands of computer experts for more than 30 years.

Because the full documentation for commands used in BSD systems consists of thou-sands of man pages, info text, and help messages, you will surely want to reachbeyond the pages of this book from time to time. Luckily, FreeBSD and other UNIXsystems include helpful information installed on the system itself. Chapter 1 containsdescriptions of how to access that information that is probably already installed, or can be easily installed, on your BSD system.

How This Book Is StructuredThis book is neither a pure reference book (with alphabetically listed components) nor aguide (with step-by-step procedures for doing tasks). Instead, the book is organized bytopics and aimed at including as many useful commands and options as we could fit in.

Chapter 1 starts by giving you a basic understanding of what BSD is and how itrelates to the operating systems that are derived from BSD, such as FreeBSD, NetBSD,and OpenBSD. Then it describes some of the vast resources available to support yourexperience with this book (such as man pages, info material, and help text). Chapter 2

76034flast.qxd:Toolbox 4/2/08 1:06 PM Page xxiii

Page 26: Christopher Negus François Caendownload.e-bookshelf.de/download/0000/5719/47/L-G... · About the Authors Christopher Negus is the author of the best-selling Fedora and Red Hat Linux

provides a quick overview of installation and then describes useful commands suchas pkg_info and pkg_add for getting and managing your BSD software.

Chapters 3, 4, 5, and 6 describe commands that a regular user may find useful on BSDsystems. Chapter 3 describes tools for using the shell, Chapter 4 covers commands forworking with files, and Chapter 5 describes how to manipulate text. Chapter 6 tellshow to work with music and image files.

Starting with Chapter 7, we get into topics relating to system administration. Creatingand checking file systems is covered in Chapter 7, while commands for doing databackups are described in Chapter 8. Chapter 9 describes how to manipulate runningprocesses, and Chapter 10 describes administrative tools for managing basic compo-nents, such as hardware modules, CPU use, and memory use.

Chapter 11 begins the chapters devoted to managing network resources by describ-ing how to set up and work with wired, wireless, and dial-up network interfaces.Chapter 12 covers text-based commands for web browsing, file transfer, file sharing,chats, and e-mail. Tools for doing remote system administration are included inChapter 13.

Chapter 14 covers how to lock down security using features such as firewalls andlogging. After that there are three appendices that provide reference information fortext editing, shell features (metacharacters and variables), and personal configura-tion files.

What You Need to Use This BookAlthough we hope you enjoy the beauty of our prose, this is not meant to be a bookyou curl up with in front of a nice fire with a glass of wine. We expect you will be sit-ting in front of a computer screen trying to connect to a network, fix a file system, oradd a user. The wine is optional.

In other words, the book is meant to be a companion as you work on a FreeBSD,NetBSD, or OpenBSD operating system. All those systems are available for the x86and x86_64 computer architectures. Some specific versions of those systems are alsoavailable for IBM PowerPC, SPARC, Intel ia64 (Itanium), and Alpha. If you don’talready have one of those systems installed, refer to Chapter 2 for information on getting and installing those systems.

All the commands in this book have been tested against FreeBSD on x86 or x86_64architecture. However, because many of these commands have been around for along time (some dating back over 30 years to the original UNIX days), most will work exactly as described here on NetBSD, OpenBSD, and other derivative systems,regardless of CPU architecture.

Introduction

xxiv

76034flast.qxd:Toolbox 4/2/08 1:06 PM Page xxiv

Page 27: Christopher Negus François Caendownload.e-bookshelf.de/download/0000/5719/47/L-G... · About the Authors Christopher Negus is the author of the best-selling Fedora and Red Hat Linux

Introduction

xxv

Many of the commands described in this book will work on other UNIX and Linuxsystems as well. Because this book focuses on FreeBSD and other BSD-based distribu-tions, descriptions will differ from other UNIX-like systems most prominently in theareas of packaging, installation, and GUI administration tools.

ConventionsTo help you get the most from the text and keep track of what’s happening, we’ve useda number of conventions throughout the book. In particular, we have created styles forshowing commands that allow us to fit as many command lines as possible in the book.

With command examples, computer output (shell prompts and messages) is shown inregular monospace font, computer input (the stuff you type) is shown in bold mono-space font, and a short description (if included) appears in italics. Here is an example:

$ ls *jpg List all JPEG files in the current directory

hat.jpg

dog.jpg

...

To save space, output is sometimes truncated (or skipped altogether). Three dots(...) are sometimes used to indicate that additional output was cut. If a command is particularly long, backslashes will appear at the end of each line to indicate thatinput is continuing to the next line. Here is an example:

# oggenc NewSong.wav -o NewSong.ogg \

-a Bernstein -G Classical \

-d 06/15/1972 -t “Simple Song” \

-l “Bernsteins Mass” \

-c info=”From Kennedy Center”

In the example just shown, you can type the backslashes to have all that informationincluded in the single command. Or, you can simply put all the information on a sin-gle line (excluding the backslashes). Note that command prompts are shown in oneof two ways:

$ Indicates a regular user prompt

# Indicates the root prompt

As noted, when a dollar sign prompt ($) appears, any user can run the command. With apound sign prompt (#), you probably need to be the root user for the command to work.

Notes and warnings appear as follows:

NOTE Warnings and notes are offset and placed in italic like this.

76034flast.qxd:Toolbox 4/2/08 1:06 PM Page xxv

Page 28: Christopher Negus François Caendownload.e-bookshelf.de/download/0000/5719/47/L-G... · About the Authors Christopher Negus is the author of the best-selling Fedora and Red Hat Linux

Introduction

xxvi

As for styles in the text:

❑ We highlight new terms and important words with italics when we introduce them.

❑ We show keyboard strokes like this: Ctrl+A. If the command requires you to typean uppercase letter, the combination will show this: Ctrl+Shift+A.

❑ We show file names, URLs, and code within the text like so: persistence.properties.

One final technique we use is to highlight text that describes what an upcoming com-mand is meant to do. For example, we may say something like, “use the followingcommand to display the contents of a file.” We’ve styled descriptions in this way to pro-vide quick visual cues to the readers, so you can easily scan the page for that com-mand you just knew had to be there.

76034flast.qxd:Toolbox 4/2/08 1:06 PM Page xxvi

Page 29: Christopher Negus François Caendownload.e-bookshelf.de/download/0000/5719/47/L-G... · About the Authors Christopher Negus is the author of the best-selling Fedora and Red Hat Linux

Starting with BSDSystems

Whether you use BSD systems every day or justtweak one once in a while, a book that presents effi-cient ways to use, check, fix, secure, and enhanceyour system can be an invaluable resource.

BSD UNIX Toolbox is that resource.

BSD UNIX Toolbox is aimed primarily at BSDpower users and systems administrators. To giveyou what you need, we tell you how to quicklylocate and get software, monitor the health andsecurity of your systems, and access networkresources. In short, we cut to the most efficientways of using BSD systems.

Our goal with BSD UNIX Toolbox is to pack a lot of useful information forusing BSD systems into a small package that you can carry around withyou. To that end, we describe:

❑ Commands — Tons of command line examples to use BSD systems in helpful and clever ways

❑ GUI Tools — Quick pointers to graphical administration tools to configure your system

❑ Software packages — Short procedures to find and download tons of applications

❑ Online resources — Listings of the best locations to find BSD forums,mailing lists, IRC channels, and other online resources

❑ Local documentation — Tools for gathering more information fromman pages, doc directories, help commands, and other resources onyour BSD system

Because you’re not a beginner with BSD systems, you won’t see a lot ofscreenshots of windows, icons, and menus. What you will see, however,

IN THIS CHAPTERFind BSD resources

Learn quick and powerful commands

Have a handy refer-ence to many usefulutilities

Work as BSD gurus do

76034c01.qxd:Toolbox 3/29/08 10:40 AM Page 1

Page 30: Christopher Negus François Caendownload.e-bookshelf.de/download/0000/5719/47/L-G... · About the Authors Christopher Negus is the author of the best-selling Fedora and Red Hat Linux

is the quickest path to getting the information you need to use your BSD system to itsfullest extent.

If this sounds useful to you, please read on.

About FreeBSD, NetBSD, and OpenBSDIn the early 1970s, AT&T released the UNIX source code to several colleges and uni-versities, allowing them to begin changing, adapting, and improving that code asthey pleased. That decision has led to the development of every major free and opensource software operating system today, not least of which are the systems based onthe Berkeley Software Distribution (BSD).

The twisty history of BSD is easy to Google for, if you care to learn the details. For ourpurposes, let’s just say that:

❑ BSD began as a set of software add-ons to AT&T’s Sixth Edition UNIX.

❑ Over the years, BSD developers split off on their own development path, rewritingsoftware with the intention of replacing all AT&T copyrighted code.

❑ In the early 1990s, AT&T’s UNIX System Laboratories sued BSD developers(Berkeley Software Design, Inc.) for copyright infringement.

❑ Although the lawsuit was eventually settled (with only a few files needing to bechanged from the BSD code), the Linux operating system was able to become aleader of open source software development while questions surrounding freeBSD were being threshed out.

❑ In 1995, the final version of BSD from Berkeley was released under the name4.4BSD-Lite, release 2. Today’s BSD operating systems, including FreeBSD,NetBSD, and OpenBSD, are all based to some extent on 4.4BSD-Lite.

Operating systems derived from BSD have a well-earned reputation for stability andsecurity. BSD was developed at a time when computing resources (disk space, networkbandwidth, and memory) were meager by today’s standards. So BSD systems wereoperated by efficient commands, instead of the bloated applications and dumbed-downgraphical interfaces often seen today.

Because of the nature of BSD systems, people running those systems required a high level of expertise. Even when simplified graphical user interfaces based on the X Window System began to appear, to effectively operate a BSD system you still needed to know about such things as kernels, device drivers, modules, and daemons. Because security came before ease-of-use, a BSD expert needed to knowhow to deal with the fact that many features they may have wanted were not installed,or were turned off, by default.

Chapter 1: Starting with BSD Systems

2

76034c01.qxd:Toolbox 3/29/08 10:40 AM Page 2