BSD UNIX Toolbox 1000+ Commands for Freebsd, Openbsd
Total Page:16
File Type:pdf, Size:1020Kb
76034ffirs.qxd:Toolbox 4/2/08 12:50 PM Page iii BSD UNIX® TOOLBOX 1000+ Commands for FreeBSD®, OpenBSD, and NetBSD®Power Users Christopher Negus François Caen 76034ffirs.qxd:Toolbox 4/2/08 12:50 PM Page ii 76034ffirs.qxd:Toolbox 4/2/08 12:50 PM Page i BSD UNIX® TOOLBOX 76034ffirs.qxd:Toolbox 4/2/08 12:50 PM Page ii 76034ffirs.qxd:Toolbox 4/2/08 12:50 PM Page iii BSD UNIX® TOOLBOX 1000+ Commands for FreeBSD®, OpenBSD, and NetBSD®Power Users Christopher Negus François Caen 76034ffirs.qxd:Toolbox 4/2/08 12:50 PM Page iv BSD UNIX® Toolbox: 1000+ Commands for FreeBSD®, OpenBSD, and NetBSD® 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-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 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, the Wiley logo, and related trade dress 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. 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 the property 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 be available in electronic books. 76034ffirs.qxd:Toolbox 4/2/08 12:50 PM Page v 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 vi 76034ffirs.qxd:Toolbox 4/2/08 12:50 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 2008 Edition. He is a member of the Madison Linux Users Group. Before 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 Linux 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 Users Group. François is a Red Hat Certified Engineer (RHCE). In his spare time, he enjoys managing enterprise Cisco networks. About the Technical Editor Thomas Blader first began dabbling in Linus/UNIX in 1993 with Yggdrasil Linux and 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 viii 76034ffirs.qxd:Toolbox 4/2/08 12:50 PM Page ix Credits Acquisitions Editor Vice President and Executive Publisher Jenny Watson Joseph B. Wikert Development Editor Project Coordinator, Cover William Bridges Lynsey Osborn Technical Editor Compositor Thomas Blader Laurie Stewart, Happenstance Type-O-Rama Production Editor Daniel Scribner Proofreader David Parise, Copy Editor Word One Michael Koch Indexer Editorial Manager Melanie Belkin Mary Beth Wakefield Production Manager Tim Tate Vice President and Executive Group Publisher Richard Swadley 76034ffirs.qxd:Toolbox 4/2/08 12:50 PM Page x Contents at a Glance Chapter 1: Starting with BSD Systems . .1 Chapter 2: Installing FreeBSD 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 . .127 Chapter 9: Checking and Managing Running Processes . .143 Chapter 10: Managing the System . .161 Chapter 11: Managing Network Connections . .185 Chapter 12: Accessing Network Resources . .205 Chapter 13: Doing Remote System Administration . .225 Chapter 14: Locking Down Security . .243 Appendix A: Using vi or Vim Editors . .263 Appendix B: Shell Special Characters and Variables . .271 Appendix C: Personal Configuration Files . .277 Index . .281 76034ftoc.qxd:Toolbox 4/2/08 1:04 PM Page xi Contents Acknowledgments xix Introduction xxi Chapter 1: Starting with BSD Systems 1 About FreeBSD, NetBSD, and OpenBSD 2 Finding BSD Resources 4 Focusing on BSD Commands 6 Finding Commands 7 Command Reference Information in BSD 8 Summary 11 Chapter 2: Installing FreeBSD and Adding Software 13 Before Installing FreeBSD 13 Installing FreeBSD 14 Booting the Install Disc 14 Starting the Install Process 15 Adding, Deleting, and Managing Software 19 Finding Software 19 Installing Software Packages (binary) 21 Removing Software Packages (binary) 22 Installing Software Using Ports (source code) 23 Getting and Installing Applications with Ports 25 Checking Packages and Ports 28 Checking Installed Packages Against Ports 28 Upgrading Ports 28 Auditing Installed Packages 29 Cleaning Up the Ports Collection 30 Summary 31 Chapter 3: Using the Shell 33 Terminal Windows and Shell Access 33 Using Terminal Windows 33 Using Virtual Terminals 35 76034ftoc.qxd:Toolbox 4/2/08 1:04 PM Page xii Contents Using the Shell 36 Using Bash History 36 Using Command Line Completion 38 Redirecting stdin and stdout 38 Using aliases 41 Tailing Files 41 Acquiring Super-User Power 41 Using the su Command 42 Delegating Power with sudo 43 Using Environment Variables 44 Creating Simple Shell Scripts 45 Editing and Running a Script 45 Adding Content to Your Script 46 Summary 50 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 and 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 Generating the locate Database 63 Finding Files with locate 64 Locating Files with find 65 Using Other Commands to Find Files 67 Finding Out More About Files 67 Listing Files 67 Verifying Files 68 Summary 69 xii 76034ftoc.qxd:Toolbox 4/2/08 1:04 PM Page 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 78 Paging Through Text 79 Paginating Text Files with pr 80 Searching for Text with grep 81 Replacing Text with sed 83 Translate or Remove 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 Starting with Audio 89 Playing Music 90 Adjusting Audio