Mac OS® X U NIX® Toolbox: 1000+ Commands for Mac OS® X Power Users

Thomas Myer, Christopher Negus, François Caen

at a Glance

Starting with UNIX on Mac OS X
New to Mac OS X ?
Using the Shell
Working with Files
Manipulating Text
Advanced Scripting
Administering File Systems
Backups a nd Removable Media
Checking and Running Processes
Managing the System
Managing Network Connections
Accessing Network Resources
Remote System Administration
Locking Down Security

e-books shop
e-books shop
Purchase Now !
Just with Paypal


Book Details
 Price
 3.00 USD
 Pages
 291 p
 File Size
 4,316 KB
 File Type
 PDF format
 ISBN
 978-0-470-47836-3
 Copyright   
 2009 by Wiley Publishing, Inc 

About the Author
Thomas Myer currently resides in Austin, Texas, where he runs Triple Dog Dare
Media, a consulting group that builds CodeIgniter applications, writes technical
documentation and copy, and works as a systems analyst for hire. He is the author of
Lead Generation on the Web, No Nonsense XML Web Development with PHP, Professional
CodeIgniter, and From Geek to Peak: Your First 365 Days as a Technical Consultant, as well
as dozens of articles on technology and business. If you have any feedback on this
book, or wish to discuss anything related to Web development, writing, or marketing,
contact him via his website at www.tripledogs.com.
Christopher Negus is the author of the Fedora and Red Hat Linux Bibles, as well as
BSD UNIX Toolbox. Chris served for eight years on development teams for the UNIX
operating system at AT&T, where UNIX was created and developed.
François Caen, through his company Turbosphere LLC, hosts and manages business
application infrastructures, 95 percent of which run on Linus systems.

Acknowledgments
I would like to acknowledge all the work done by the developers, project managers,
analysts, and others on the Mac OS X team. They’ve created something wonderful in
this stable, secure, and speedy little OS. I’ve had a great deal of fun and joy working
with it, which is more than most people can say when it comes to computing.
Special thanks to Jenny Watson for being such a joy to work with. Even more thanks
to Bill Bridges, who took my calls, answered my questions, and kept things moving
forward even when it looked like we were going to become permanently stuck in the weeds.
I wouldn’t have been able to work on this book if it weren’t for my ever-loving and
ever-patient wife, Hope. Your name says it all—you fill my life with hope and joy and
love and…well, everything. Thanks for being such a champ.
—Thomas Myer

Table of Contents
Introduction xix
Chapter 1: Starting with UNIX on M ac OS X 1
About FreeBSD, N etBSD, and OpenBSD 2
Finding Mac O S X R esources 4
Focusing on Mac O S X C ommands 4
Finding Commands 5
Command Reference Information in UNIX 6
Summary 9
Chapter 2 : New to Mac OS X? 11
What Is Mac O S X U NIX? 11
Finding Terminal and Utilities 12
Directory Structure 16
Your Home Directory 18
Spotlight 19
Getting and Using Fink 21
Mounting and Unmounting Drives 23
Learning to Love Launchd 25
Summary 25
Chapter 3: U sing the Shell 27
Terminal Windows and Shell Access 27
Using the Shell 28
Using bash History 29
Using Command-Line Completion 30
Redirecting stdin and stdout 31
Using Aliases 33
Tailing Files 34
Acquiring Super User Power 34
Using Environment Variables 35
Creating Simple Shell Scripts 36
Editing and Running a Script 36
Adding C ontent to Your Script 37
Summary 41
Chapter 4: Working with Files 43
Understanding File Types 43
Using Regular Files 43
Using Directories 44
Using S ymbolic and Hard Links 45
Using Device Files 46
Using Named Pipes a nd S ockets 46
Setting File and Directory Permissions 47
Changing Permissions w ith chmod 48
Setting the umask 51
Changing Ownership 51
Traversing the File System 51
Copying Files 53
Searching for Files 55
Generating the lo cate Database 55
Finding Files with locate 56
Locating Files with find 57
Using Other Commands to Find Files 59
Finding Out More About Files 59
Listing Files 59
Verifying Files 60
Summary 62
Chapter 5: Manipulating Text 63
Matching Text with Regular Expressions 63
Editing Text Files 64
Using the Pico and Nano Editors 65
Listing, Sorting, and Changing Text 67
Listing Text Files 67
Paging Through Text 68
Paginating Text Files with pr 69
Searching for Text with grep 69
Replacing Text with sed 71
Translating or Removing Characters with tr 73
Checking Differences Between Two Files with diff 73
Using awk and cut to Process C olumns 75
Summary 76
Chapter 6: A dvanced Scripting 77
Shell Scripting on Mac O S X 77
Creating a Basic Shell Script 78
Adding C ommand-Line Arguments 80
Things t o Watch Out For 83
Using the Script C ommand 83
AppleScripting 84
Working with the Open Command 87
Summary 90
Chapter 7: Administering File Systems 91
Understanding File System Basics 91
Setting Up the Disk I nitially 92
Checking Your Disk Setup 92
Understanding File System Types 92
Creating and Managing File Systems 94
Partitioning Hard Disks 94
A Better Option: Nondestructive Partitioning 95
Mounting and Unmounting File Systems 96
Checking File Systems 97
Finding Out A bout File System Use 99
Summary 101
Chapter 8: Backups and Removable Media 103
Backing Up Data to Compressed Archives 103
Creating Backup Archives with tar 103
Using C ompression Tools 105
Listing, Joining, and Adding Files to tar Archives 107
Backing Up over a Network 107
Backing Up tar Archives o ver ssh 108
Backing Up Files w ith rsync 109
Backing Up to C D or DVD 110
Working with Time Machine and Time Capsule 111
Summary 112
Chapter 9: Checking and Running Processes 115
Listing Active Processes 116
Viewing Active Processes w ith ps 116
Watching Active Processes with top 121
Finding and Controlling Processes 123
Using grep and pgrep to Find Processes 123
Using fuser to Find Processes 124
Summary 131
Chapter 10: Managing the System 133
Monitoring Resources 133
Monitoring Memory Use 134
Monitoring C PU U sage 135
Monitoring S torage Devices 136
Mastering T ime 137
Changing Time Zone 137
Displaying and S etting Time and Date 137
Using Network Time Protocol to S et Date/Time 139
Checking Uptime 139
Starting and Stopping Your System 140
Straight to the Kernel 141
Summary 141
Chapter 11: Managing Network Connections 143
Configuring Network Interfaces 143
Managing Network Interface Cards 144
Managing Network Connections 147
Starting and Stopping Network Connections 148
Starting and Stopping Network Services 149
Checking Name Resolution 149
Troubleshooting Network Problems 151
Checking Connectivity to a Host 152
Checking Address Resolution Protocol (ARP) 153
Tracing Routes t o Hosts 154
Displaying netstat C onnections a nd S tatistics 156
Summary 157
Chapter 12: A ccessing Network Resources 159
Transferring Files 159
Downloading Files with wget 159
Transferring Files w ith curl 161
Transferring Files w ith FTP Commands 162
Using S SH Tools t o Transfer Files 164
Sharing Remote Directories 165
Sharing Remote Directories w ith NFS 165
Sharing Remote Directories w ith S amba 167
Chatting with Friends in I RC 172
Using Text-Based E‑mail Clients 173
Summary 175
Chapter 13: Remote System Administration 177
Remote Login and Tunneling with SSH 177
Configuring S SH 179
Logging in Remotely with ssh 179
Using screen: A Rich Remote Shell 184
Reconnecting to a s creen S ession 185
Naming screen Sessions 186
Sharing s creen S essions 186
Using a Remote Windows Desktop 186
Using Remote Desktop and Applications 187
Sharing Your Desktop Using V NC 188
Summary 189
Chapter 14: Locking Down Security 191
Working with Users and Groups 192
Managing Users t he GUI Way 192
Checking on Users 193
Configuring the Built-in Firewall 195
Working with System Logs 197
Summary 197
Appendix A : U sing vi or Vim Editors 199
Starting and Quitting the vi Editor 200
Moving Around in v i 201
Changing and Deleting Text in v i 202
Using Miscellaneous C ommands 204
Modifying Commands with Numbers 204
Using Ex C ommands 205
Working in V isual Mode 206
Summary 206
Appendix B : S hell Special Characters and Variables 207
Using Special Shell Characters 207
Using Shell Variables 208
Appendix C : Personal Configuration Files 211
Appendix D : A ppleScript C ommand Summary 215
Appendix E : Fink Package Summary 219
Appendix F: Perl Primer 239
Introducing Perl 239
Checking Links on a Website 240
The Entire S cript 241
Initializing the Script and Loading Packages 242
Targeting the URL and Extracting Links 243
Processing the @links Array 244
Running the S cript 245
Extending the Script 246
Index 247

Bookscreen
e-books shop

Introduction
Mac OS X UNIX Toolbox is loosely based on the BSD UNIX Toolbox written by Chris
Negus and François Caen. When I was asked by Wiley to extend what they had done
into the world of Mac OS X, I heartily agreed to do so, partly because the original
was such an excellent resource.
From the very beginning, I decided to keep to the spirit and structure of the original
title as much as I could. Thankfully, about 90 percent of what you experience UNIXwise
on Mac OS X is the same as on BSD or Linux environments, so I was able, for
the most part, to abide by this agreement. In some cases, though, I had to nip and
tuck a few sections; in others, I had to add a bit back in.
At the end of the day, what you hold is a handbook with more than 1,000 specific
command lines to help you become a Mac OS X 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 Mac OS X system.
Of course, Mac OS X being what it is, not everything in this book is about the command
line (although most of it is). In some cases, I show you not only how to do
things on the venerated command line, but also how to take advantage of the Mac
OS X GUI. Either way, you learn how to leverage UNIX to do your job.

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

The bottom line is that you want to find quick and efficient ways of getting Mac OS X
systems working at peak performance. These may be a few desktop systems at work,
a file and print server at your school, or a home web server that you’re setting up
mostly for fun.

In the best case, you should already have some experience with BSD, Linux, or other
UNIX-like systems. However, if you are a computer professional with skills managing
other types of operating systems, such as Windows, you should be able to leverage
your knowledge and use the specific commands covered in the book.

How T his Book Is Structured
This book is neither a pure reference book (with alphabetically listed components) nor a
guide (with step-by-step procedures for doing tasks). Instead, the book is organized by
topic, and includes the most useful commands and options you will likely work with.
Chapter 1 provides you with a basic understanding of what Mac OS X is and how it
relates 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 your
experience with this book, such as man pages, info material, and help text. Chapter
2 provides a quick overview of the Mac OS X environment and how you can set it up
to get easy access to UNIX tools. It also includes a quick introduction to Fink, a package
manager that will enable you to install additional tools mentioned in this book.
Chapters 3, 4, 5, and 6 describe commands that a regular user may find useful on
Mac OS X systems. Chapter 3 describes tools for using the shell, Chapter 4 covers
commands for working with files, and Chapter 5 describes how to manipulate
text. Chapter 6 walks you through more advanced shell scripting and introduces AppleScripting.
Starting with Chapter 7, we get into topics relating to system administration.
Creating and checking file systems is covered in Chapter 7, while commands for
doing data backups are described in Chapter 8. Chapter 9 explains how to manipulate
running processes, and Chapter 10 describes administrative tools for managing
basic components, such as hardware modules, CPU use, and memory use.
Chapter 11 begins the chapters devoted to managing network resources by describing
how to set up and work with network interfaces. Chapter 12 covers text-based
commands for file transfer, file sharing, chats, and e‑mail. Tools for doing remote
system administration are included in Chapter 13.
Chapter 14 covers how to lock down security, using features such as firewalls and
logging. Following that are six appendixes that provide additional reference information
for text editing, shell features (metacharacters and variables), personal configuration
files, AppleScript commands, a quick Perl primer, and some interesting
packages available via Fink that you might want to explore.

What You Need to Use This Book
This is definitely not a book you curl up with on your next vacation. Nor is it meant
to entertain you. Throughout, I fully expect you to be sitting in front of a Mac OS X
system, scratching your head with one hand and holding this book in the other, looking
for a solution.

In other words, the book is meant to be a companion as you work on a problem
related to Mac OS X. You’ll probably be working on a desktop system at home or
work, but a fair number of you will be working on a file, web, or print server running Mac OS X.
All the commands in this book have been tested against a 64-bit x86 system running
Mac OS X 10.5 (Leopard). Specifically, I’m running a MacBook Pro. My technical editor
checked everything on a MacBook Pro (running Mac OS X 10.5) primarily, but he
also used a MacBook (running Mac OS X 10.5) and (once) a PowerMac (running Mac OS X 10.4).

I assume that you’re running Leopard, but don’t despair if you’re on Tiger, as most
of what is covered here also pertains to that earlier release. In addition, please note
that nearly every command available from the shell has been around for a long time
(some dating back more than 30 years to the original UNIX days), and most will
work exactly as described here on NetBSD, OpenBSD, and other derivative systems,
regardless of CPU architecture.

Furthermore, many of the commands described in this book will also work on other
UNIX and Linux systems. Because this book focuses on Mac OS X, descriptions will
differ from other UNIX-like systems most prominently in the areas of packaging,
installation, and GUI administration tools.
Previous Post Next Post