Table of Contents
Introduction xix
Chapter 1: Starting with UNIX on Mac OS X 1
About FreeBSD, NetBSD, and OpenBSD 2
Finding Mac OS X Resources 4
Focusing on Mac OS X Commands 4
Finding Commands 5
Command Reference Information in UNIX 6
Summary 9
Chapter 2: New to Mac OS X? 11
What Is Mac OS X UNIX? 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: Using 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 Content to Your Script 37
Summary 41
Chapter 4: Working with Files 43
Understanding File Types 43
Using Regular Files 43
Using Directories 44
Using Symbolic and Hard Links 45
Using Device Files 46
Using Named Pipes and Sockets 46
Setting File and Directory Permissions 47
Changing Permissions with chmod 48
Setting the umask 51
Changing Ownership 51
Traversing the File System 51
Copying Files 53
Searching for Files 55
Generating the locate 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 Columns 75
Summary 76
Chapter 6: Advanced Scripting 77
Shell Scripting on Mac OS X 77
Creating a Basic Shell Script 78
Adding Command-Line Arguments 80
Things to Watch Out For 83
Using the Script Command 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 Initially 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 About 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 Compression Tools 105
Listing, Joining, and Adding Files to tar Archives 107
Backing Up over a Network 107
Backing Up tar Archives over ssh 108
Backing Up Files with rsync 109
Backing Up to CD 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 with 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 CPU Usage 135
Monitoring Storage Devices 136
Mastering Time 137
Changing Time Zone 137
Displaying and Setting Time and Date 137
Using Network Time Protocol to Set 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 to Hosts 154
Displaying netstat Connections and Statistics 156
Summary 157
Chapter 12: Accessing Network Resources 159
Transferring Files 159
Downloading Files with wget 159
Transferring Files with curl 161
Transferring Files with FTP Commands 162
Using SSH Tools to Transfer Files 164
Sharing Remote Directories 165
Sharing Remote Directories with NFS 165
Sharing Remote Directories with Samba 167
Chatting with Friends in IRC 172
Using Text-Based E‑mail Clients 173
Summary 175
Chapter 13: Remote System Administration 177
Remote Login and Tunneling with SSH 177
Configuring SSH 179
Logging in Remotely with ssh 179
Using screen: A Rich Remote Shell 184
Reconnecting to a screen Session 185
Naming screen Sessions 186
Sharing screen Sessions 186
Using a Remote Windows Desktop 186
Using Remote Desktop and Applications 187
Sharing Your Desktop Using VNC 188
Summary 189
Chapter 14: Locking Down Security 191
Working with Users and Groups 192
Managing Users the GUI Way 192
Checking on Users 193
Configuring the Built-in Firewall 195
Working with System Logs 197
Summary 197
Appendix A: Using vi or Vim Editors 199
Starting and Quitting the vi Editor 200
Moving Around in vi 201
Changing and Deleting Text in vi 202
Using Miscellaneous Commands 204
Modifying Commands with Numbers 204
Using Ex Commands 205
Working in Visual Mode 206
Summary 206
Appendix B: Shell Special Characters and Variables 207
Using Special Shell Characters 207
Using Shell Variables 208
Appendix C: Personal Configuration Files 211
Appendix D: AppleScript Command Summary 215
Appendix E: Fink Package Summary 219
Appendix F: Perl Primer 239
Introducing Perl 239
Checking Links on a Website 240
The Entire Script 241
Initializing the Script and Loading Packages 242
Targeting the URL and Extracting Links 243
Processing the @links Array 244
Running the Script 245
Extending the Script 246
Index 247