About the Book

Lose the mouse and start taking advantage of the power of Mac OS X's Unix core.

Welcome to the web site for the book Mac OS X Unix, 101 Byte-Sized Projects by Adrian Mayo and published by InsideMac Press and Peachpit Press.

In this practical and approachable book, Adrian guides readers through 101 compact and essential Unix projects filled with tips and advice. You'll learn Unix through doing, and you'll learn how to apply Unix to solve real-world problems. Newcomers will gain a useful knowledge of Unix, while those already familiar with the command line will expand their skills.

Whether it's to search for files, search and automatically edit file content, use regular expressions, mount disks and network shares, create user accounts, configure Apache, write shell scripts to automate tasks, or any one of 94 other tasks, you'll find a project that shows you how.

This site reproduces the book's introduction and lists the 101 projects. It presents supplementary material for particular projects, written in response to readers' feedback. Example code is available for downloading to save you from typing. See the Site Contents to the left.

If you spot an error, require help in completing a particular project, have any suggestions or contributions to add to the supplementary material, contact Adrian.

Introduction to the Book

This book is for you if you have a problem to solve or a task to complete: Working at the Unix command line often provides the quickest and easiest solution. Although a modern Unix environment such as Mac OS X provides a graphical method of working, the real power still lies at the Terminal and in typing commands. The Unix command line lets you work with your Mac in ways that are difficult or even impossible graphically, unlocking the hidden workings of Apple's OS and unleashing a wealth of powerful free software. Clicking a button may be an easy way to perform a pre-packaged action, but it doesn't give you the expressive power of a set of written commands.

Here's a sample page taken from the book.

Philosophy

Plenty of books teach Unix theory, covering a single subject like Unix itself, the Bash shell, shell scripting, the vim or emacs text editor, the awk text processing language, the Apache web server, networking, firewalls, etc. That's a lot of books, a lot of reading, and a lot of theory. Ninety percent of you don't have the inclination or time to follow that route. You learn on-demand and want to cut to the chase to get a specific job done. You want to focus on the micro-topic that solves your current problem or gives you the knowledge to work out your own solution. Moreover, because most solutions involve more than a single command, you want to know of the relevant techniques, technologies, and commands, and how to use them in combination.

These considerations lead to the book's approach. For 101 of the most common tasks, it explores the most appropriate commands and shows how to use and combine them in the context of the task. This is different from the traditional theory approach that considers a command in its own right and then asks, What can I do with this command?

The book uses a 90:10 philosophy. Ninety percent of the usefulness of a tool or technology lies in just ten percent of its functionality. Awk (a text processing language) is a good example - very powerful and commonly used, but rarely stretched beyond its ten percent headline functionality. By taking the 90:10 approach, we combine ten books in one, illustrate a broad range of topics that you'll encounter every day, and show techniques used in combination, not isolation.

But I Love my Mouse

Mac OS X provides a powerful and elegant graphical user interface, so you might find it counterintuitive to drop into the Unix command line to get a job done. But as with a powerful car, sometimes you need to get under the hood to squeeze out all the performance it can deliver.

Even if you don't have an immediate need, working through some of the projects in this book is a Unix analog to the pointing, clicking, and dragging way in which most of us learned the Mac OS. It'll help you gain familiarity and confidence in using Unix. When you've made friends with the man pages, practiced stringing commands together, written a few scripts, you'll begin to know and appreciate the power under the Aqua-colored hood.

What You'll Learn

You'll learn how to apply Unix and achieve results. Along the way, you'll learn Unix commands, techniques, and technologies. Basic Unix is covered in Chapter 1.

From the 101 projects in this book you'll learn how to:

  • Locate then edit many files automatically
  • Find files and commands anywhere in the file system as you can with Apple's Spotlight, and process them at the same time.
  • Write shell scripts that execute a series of commands automatically
  • Search file content for particular text or patterns of text
  • Use the Unix manual to full effect to learn about new commands and technologies
  • Manage your Mac's hardware, software, user accounts, and network settings
  • Mount local disc drives, removable media, and shares from other machines
  • Use and customize the Bash and Tcsh shells - the Unix equivalent to using and customizing your desktop and the Finder
  • Display, edit, sort, compare, compress, and archive files

You'll also learn techniques and technologies such as:

  • Globbing and pattern matching operators that allow you to select many files at once, like all JPEG files or all files starting letter-to
  • Scripting commands such as sed and awk to search for and transform the text content of files
  • Redirection and pipelining that enable you to save the results of commands and use commands in combination
  • Users, groups, and Unix file permissions that protect both your files from unauthorized access by other users, and the system files from being deleted or damaged
  • Hard and soft links, which are like Mac OS aliases
  • Regular expressions written to describe patterns of text for which you can search
  • Unix text editors
  • Scheduling and periodic maintenance to automatically perform particular tasks at specified times
  • Server technologies such as the Apache web server, Unix Network File System (NFS) for sharing files with other Unix machines, File Transfer Protocol (FTP) for transferring files between computers, and the Domain Naming System (DNS) that translates names such as www.apple.com into Internet Protocol addresses (IP addresses)

The 101 Projects

Here's a list of the 101 projects. Although they can be read sequentially, the book was written for "random access". You'll probably pick it up when you seek a solution to a problem. Each chapter groups projects that cover similar tasks, so to find a suitable project start with the Table of Contents and choose the chapter that seems closest to your task. Scan the list of projects in the chapter and choose the project that looks like the closest fit. Then read the introduction to confirm it's the right one; each project introduction starts with a typical question that the project will answer, and then outlines the material it covers.

Table of Contents

Chapter 1: Absolute Basics
PROJECT 1: Lose the Mouse PROJECT 2: Learn Basic Unix PROJECT 3: Get the Most from the Unix Manual PROJECT 4: Learn Bash Shell Basics PROJECT 5: Discover Other Shells PROJECT 6: Use Redirection and Pipelining PROJECT 7: Know Your Users and Groups PROJECT 8: Manage File Permissions PROJECT 9: Learn About Shell Scripts PROJECT 10: Write Shell Scripts
Chapter 2: Browse and Search the File System
PROJECT 11: Globbing with [^*?] PROJECT 12: Power Globbing PROJECT 13: Change Your Working Directory PROJECT 14: Navigate the File System PROJECT 15: Find Files by Name PROJECT 16: Find Unix Commands PROJECT 17: Get Clever Finding Files PROJECT 18: Use find, -exec, and xargs PROJECT 19: Understand Links and Aliases PROJECT 20: File Finding Tips
Chapter 3: Work with File Content
PROJECT 21: Display Text Files PROJECT 22: Display Binary Files PROJECT 23: Search File Content PROJECT 24: View File Differences PROJECT 25: View Three-Way Differences PROJECT 26: Sort and Compare Text Files PROJECT 27: Compress Files PROJECT 28: Archive Files PROJECT 29: File-Content Tips
Chapter 4: Edit Files
PROJECT 30: Edit with nano PROJECT 31: Edit with emacs PROJECT 32: Edit with vim PROJECT 33: Learn Advanced vim PROJECT 34: Use vim Windows PROJECT 35: Configure vim PROJECT 36: Edit with GUI-Based Editors
Chapter 5: Keep an Eye on Your Mac
PROJECT 37: Profile the Hardware PROJECT 38: Profile the System Software PROJECT 39: View Processes PROJECT 40: Manage Processes PROJECT 41: View System Log Files PROJECT 42: Manage the System Log Daemon PROJECT 43: System Voyeur Tips
Chapter 6: Make the Most of the Shell
PROJECT 44: Customize the Terminal PROJECT 45: Customize the Bash Shell PROJECT 46: Customize the Tcsh Shell PROJECT 47: Customize Shell Startup PROJECT 48: Customize Command History PROJECT 49: Use Command-Line Recall PROJECT 50: Change the Command Path PROJECT 51: Define Shell Aliases PROJECT 52: Define Shell Functions PROJECT 53: Edit Command Lines PROJECT 54: Understand Bash Internals PROJECT 55: Run Background Jobs PROJECT 56: Cool Shell Tips
Chapter 7: Programmatically Change Files
PROJECT 57: Edit Text Files PROJECT 58: Batch-Edit Files PROJECT 59: Learn the sed Stream Editor PROJECT 60: Learn the awk Text Processor PROJECT 61: Learn Advanced sed PROJECT 62: Learn Advanced awk PROJECT 63: Editing Tips
Chapter 8: Administer the System
PROJECT 64: Get Information about Users PROJECT 65: Manage User Accounts PROJECT 66: Manage File Systems PROJECT 67: Look after Your Disks PROJECT 68: Mount and Unmount Local Disks PROJECT 69: Delete Immutable Files PROJECT 70: Schedule Commands with at PROJECT 71: Schedule Commands with cron PROJECT 72: Manage Periodic Maintenance PROJECT 73: Manage Network Settings PROJECT 74: System Tips
Chapter 9: Learn Shell Scripting
PROJECT 75: Use Functions in Scripts PROJECT 76: Use Bash Parameter Expansion PROJECT 77: Learn Regular Expressions PROJECT 78: Be Clever with Regular Expressions PROJECT 79: Use Here-Documents in Scripts PROJECT 80: Understand Shell Quoting PROJECT 81: Write Complex Bash Conditions PROJECT 82: Debug Your Scripts PROJECT 83: Batch-Process Files PROJECT 84: A Bash and Tcsh Reference PROJECT 85: Take Advantage of Subshells PROJECT 86: Trap and Handle Unix Signals PROJECT 87: Scripting Tips
Chapter 10: Network in Unix
PROJECT 88: Mount Shares PROJECT 89: Set up an NFS Server PROJECT 90: Probe Networks PROJECT 91: Resolve Hostnames PROJECT 92: Configure Apache PROJECT 93: Configure Apache More PROJECT 94: Configure the FTP Service PROJECT 95: Networking Tips
Chapter 11: Discover More Commands
PROJECT 96: Discover Useful Utilities PROJECT 97: Connect with Aqua PROJECT 98: Open Aqua Items PROJECT 99: OS XSpecific Commands PROJECT 100: Unix Command Reference PROJECT 101: Have Fun
Appendix: Unix Terminology Reference

Supplementary Material

This section presents supplementary material for some of the projects. It includes explanatory text to supplement that in the book, extra examples, clarifications of the book text, and corrections. (See also Errata.)

The material is written in response to readers' feedback. If you spot an error, require help in completing a particular project, have any suggestions or contributions to add to the supplementary material, then email Adrian using the contact link to the left.

To see supplementary information for a project, select it from the list below.

(There's no supplementary material at the moment.)

Code to Download

To save you from typing you may download the code extracts presented in the book. Click to download a zipped tar file. To extract it, change to the directory containing the download and type:

$ tar -xzf 101-downloads.tgz

This will create a directory called 101-downloads. In this directory you'll find many of the code extracts used throughout the book. Each file is named according to the project and example to which it pertains.

You'll also find Bash configuration files which contain settings used and suggested in the book. Copy these files to their proper places to try them out (but make sure you backup the originals first), then start a new Bash shell.

The Bash configuration files are:

  • profile (copy to /etc/profile)
  • bashrc (copy to /etc/bashrc)
  • dot-bash_profile (copy to ~/.bash_profile)
  • dot-bashrc (copy to ~/.bashrc)

The file dot-bashrc contains aliases and functions suggested throughout the book, grouped by project number.

Errata

Here's a list of the known errors. If you spot an error, email Adrian using the contact link to the left. If you would like to see additional explanatory information on any of the projects, or require help, see Supplementary Material.

(There's no errata, so far...)