Preface

Once upon a time, Unix came with only a few standard utilities. If you were lucky, it included a C compiler. When setting up a new Unix system, you’d have to crawl the Net looking for important software: Perl, gcc, bison, flex, less, Emacs, and other utilities and languages. That was a lot of software to download through a 28.8-Kbps modem. These days, Unix distributions come with many more features, and more and more users are gaining access to a wide-open pipe.

Free Linux distributions pack most of the GNU tools onto a CD-ROM, and now commercial Unix systems are catching up. Solaris comes with a companion CD of free software including a big selection of GNU utilities, and just about every flavor of Unix (including Mac OS X) now includes Perl. Mac OS X also comes with many tools, most of which are open source and complement the tools associated with Unix.

This book serves as a bridge for Unix developers and system administrators who’ve been lured to Mac OS X because of its Unix roots. When you first launch the Terminal application, you’ll find yourself at home in a Unix shell. However, Apple’s credo is “Think Different,” and you’ll soon find yourself doing things a little differently. Some of the standard Unix utilities you’ve grown accustomed to may not be there, /etc/passwd and /etc/group have been supplanted with something called Directory Services, and when it comes to developing applications, you’ll find that things like library linking and compiling have a few new twists to them.

Despite all the beauty of Mac OS X’s Aqua interface, you’ll find that some things are different on the Unix side. But rest assured, the changes are easy to deal with if you know what to do. This book is your survival guide for taming the Unix side of Mac OS X.

Audience for This Book

This book is aimed at Unix developers—a category that includes programmers who have switched to Linux from a non-Unix platform—as well as web developers who spend most of their time in ~/public_html over an ssh connection, and experienced Unix hackers. In catering to such a broad audience, we’ve chosen to include some material that advanced users might consider basic. However, this choice makes the book accessible to all Unix programmers who’ve switched to Mac OS X as their operating system of choice, whether they have been using Unix for 1 year or 10. If you are coming to Mac OS X with no Unix background, we suggest that you start with Learning Unix for Mac OS X Tiger by Dave Taylor (O’Reilly) to get up to speed with the basics.

Organization of This Book

This book is divided into four parts. Part I helps you map your current Unix knowledge to the world of Mac OS X. Part II discusses compiling and linking applications. Part III takes you into the world of Fink and covers packaging. Part IV discusses using Mac OS X as a server and provides some basic system management information. Appendix A provides useful reference information.

Here’s a brief overview of what’s in the book.

Part I, Getting Around

This part of the book orients you to Mac OS X’s unique way of expressing its Unix personality.

Chapter 1, Inside the Terminal

This chapter provides you with an overview of the Terminal application, including a discussion of the differences between the Terminal and the standard Unix xterm.

Chapter 2, Searching and Metadata

This chapter introduces Spotlight, a subsystem for searching your Mac. In this chapter, you’ll learn how to access this powerful metadata store from the command line.

Chapter 3, Files and Filesystems

Here you’ll learn about the layout of the Mac OS X filesystem, with descriptions of key directories and files.

Chapter 4, Startup

This chapter describes the Mac OS X boot process, from when the Apple icon first appears on your display to when the system is up and running.

Chapter 5, Directory Services

This chapter gets you started with Mac OS X’s powerful Directory Services system, which replaces or complements the standard Unix flat files in the /etc directory.

Chapter 6, Printing

This chapter explains how to set up a printer under Mac OS X and shows you around CUPS, the open source printing engine under Mac OS X’s hood.

Chapter 7, The X Window System and VNC

In this chapter, you’ll learn how to install and work with the X Window System and how to use both built-in Mac OS X and third-party tools for establishing VNC connections between Mac OS X and other Unix systems.

Chapter 8, Third-Party Tools and Applications

This chapter introduces some third-party applications that put a new spin on Unix features, such as SSH/SFTP frontends, applications, the statistical package R, and multimedia-related applications.

Chapter 9, Dual-Boot and Beyond

Mac OS X isn’t the only operating system you can run on your Mac. In this chapter, you’ll learn how you can run many operating systems on your Mac, perhaps even two or three at a time.

Part II, Building Applications

Although Apple’s C compiler is based on the GNU Compiler Collection (GCC), there are important differences between compiling and linking on Mac OS X and on other platforms. This part of the book describes these differences.

Chapter 10, Compiling Source Code

This chapter describes the peculiarities of the Apple C compiler, including using macros that are specific to Mac OS X, working with precompiled headers, and configuring a source tree for Mac OS X.

Chapter 11, Libraries, Headers, and Frameworks

Here we discuss building libraries, linking, and miscellaneous porting issues you may encounter with Mac OS X.

Part III, Working with Packages

There are several packaging options for software that you compile, as well as for software you obtain from third parties. This part of the book covers software packaging on Mac OS X.

Chapter 12, Fink

In this chapter you’ll learn all about Fink, a package management system and porting effort that brings many open source applications to Mac OS X.

Chapter 13, MacPorts

MacPorts offers another way to install lots of open source software on your Mac. You’ll learn all about it in this chapter.

Chapter 14, Creating and Distributing Installable Software

This chapter describes the native package formats used by Mac OS X, as well as packaging options you can use to distribute applications.

Part IV, Serving and System Management

This part of the book talks about using Mac OS X as a server and discusses system administration.

Chapter 15, Using Mac OS X As a Server

In this chapter, you’ll learn about setting up your Macintosh to act as a server, selectively letting traffic in (even through a Small Office/Home Office firewall such as the one found in the AirPort base station), setting up Postfix, and setting up and configuring MySQL and PostgreSQL.

Chapter 16, System Management Tools

This chapter describes commands for monitoring system status and configuring the operating system.

Chapter 17, Other Programming Languages: Perl, Python, Ruby, and Java

This chapter describes the versions of Perl, Python, Ruby, and Java that ship with Mac OS X, as well as optional modules that can make your experience much richer.

Appendix

The appendix includes reference information that will be useful to newcomers.

Appendix A

If you are totally new to Mac OS X, this appendix will get you up to speed with the basics of its user interface. It also introduces terminology that we use throughout the book.

Xcode Tools

This book assumes that you have installed the Xcode tools, which include the latest version of Apple’s port of gcc. If you bought a boxed version of Mac OS X Tiger or Leopard, you can find the installer for Xcode in the Xcode folder on the same DVD that you used to install Mac OS X. Boxed versions of earlier releases of Mac OS X included Xcode on a separate CD-ROM. If you’d like to be absolutely sure that you have the latest versions of the tools, they are available to Apple Developer Connection (ADC) members at http://connect.apple.com.

Where to Go for More Information

Although this book will get you started with the Unix underpinnings of Mac OS X, there are many online resources that can help you get a better understanding of Unix for Mac OS X:

Apple’s Open Source mailing lists page

This page leads to all the Apple-hosted Darwin mailing lists and includes links to list archives.

http://developer.apple.com/darwin/mail.html
The Darwin project

Darwin is a complete Unix operating system for x86 and PowerPC processors. Mac OS X is based on the Darwin project. Spend some time at the project’s web page to peek as deep under Mac OS X’s hood as is possible.

http://www.opensource.apple.com/darwinsource/
Fink

Fink is a collection of open source Unix software that has been ported to Mac OS X. It is based on the Debian package management system and includes utilities to easily mix precompiled binaries and software built from source. Fink also includes complete GNOME and KDE desktop distributions.

http://fink.sourceforge.net
MacPorts

MacPorts (formerly known as DarwinPorts), a project of OpenDarwin, is an open source community-based project that provides a unified porting system for Darwin, Mac OS X, FreeBSD, and Linux. At the time of this writing, it includes thousands of ports, including the GNOME desktop system. The MacPorts project is hosted by Apple, Inc.

http://www.macports.org
MacOSXHints

MacOSXHints presents a collection of reader-contributed tips, along with commentaries from people who have tried the tips. It includes an extensive array of Unix tips.

http://www.macosxhints.com
Stepwise

Before Mac OS X, Stepwise was the definitive destination for OpenStep and WebObjects programmers. Now Stepwise provides news, articles, and tutorials for Cocoa and WebObjects programmers.

http://www.stepwise.com
VersionTracker

VersionTracker keeps track of software releases for Mac OS X and other operating systems.

http://www.versiontracker.com
MacUpdate

MacUpdate also tracks software releases for Mac OS X.

http://www.macupdate.com
FreshMeat’s Mac OS X section

FreshMeat catalogs and tracks the project history of thousands of applications (mostly open source).

http://osx.freshmeat.net

Conventions Used in This Book

The following typographical conventions are used in this book:

Italic

Used to indicate new terms, URLs, filenames, file extensions, directories, commands and options, modules, and Unix utilities. For example, a path in the filesystem will appear in the text as /Applications/Utilities.

Constant width

Used to show functions, variables, keys, attributes, the contents of files, or the output from commands.

Constant width bold

Used in examples to show commands or other text that should be typed literally by the user.

Constant width italic

Used in examples and commands to show text that should be replaced with user-supplied values, and to highlight comments in command output.

Menus/Navigation

Menus and their options are referred to in the text as File→Open, Edit→Copy, etc. Arrows are also used to signify a navigation path when using window options; for example, System Preferences→Accounts→username→Password means that you should launch System Preferences, click the icon for the Accounts preference panel, select the appropriate username, and then click on the Password pane within that panel.

Pathnames

Pathnames are used to show the location of a file or application in the filesystem. Directories (or folders for Mac and Windows users) are separated by a forward slash. For example, if you’re told to “...launch the Terminal application (/Applications/Utilities),” it means you can find the Terminal application in the Utilities subfolder of the Applications folder.

$, #

The dollar sign ($) is used in some examples to show the user prompt for the bash shell; the hash mark (#) is the prompt for the root user.

Menu symbols

When looking at the menus for any application, you will see some symbols associated with keyboard shortcuts for particular commands. For example, to open a document in Microsoft Word, you could go to the File menu and select Open (File→Open), or you could issue the keyboard shortcut ⌘-O.

Figure 1 shows the symbols used in the various menus to denote a keyboard shortcut.

These symbols, which appear in Mac OS X’s menus, are used for issuing keyboard shortcuts so you can quickly work with an application without having to use the mouse
Figure 1. These symbols, which appear in Mac OS X’s menus, are used for issuing keyboard shortcuts so you can quickly work with an application without having to use the mouse

Rarely will you see the Control symbol used as a menu command option; it’s more often used in association with mouse-clicks to emulate a right-click on a two-button mouse or for working with the bash shell.

Note

This icon signifies a tip, suggestion, or general note.

Warning

This icon indicates a warning or caution.

Comments and Questions

Please address comments and questions concerning this book to the publisher:

O’Reilly Media, Inc.
1005 Gravenstein Highway North
Sebastopol, CA 95472
800-998-9938 (in the United States or Canada)
707-829-0515 (international/local)
707-829-0104 (fax)

To comment or ask technical questions about this book, send email to:

We have a website for the book, where we list examples, errata, and any plans for future editions. The site also includes a link to a forum where you can discuss the book with the author and other readers. You can access this site at:

http://www.oreilly.com/catalog/9780596520625/

For more information about books, conferences, Resource Centers, and the O’Reilly Network, see the O’Reilly website at:

http://www.oreilly.com

Safari® Books Online

Note

When you see a Safari® Books Online icon on the cover of your favorite technology book, that means the book is available online through the O’Reilly Network Safari Bookshelf.

Safari offers a solution that’s better than e-books. It’s a virtual library that lets you easily search thousands of top tech books, cut and paste code samples, download chapters, and find quick answers when you need the most accurate, current information. Try it for free at http://safari.oreilly.com.

Acknowledgments from the Previous Editions

This book builds on the first edition of Mac OS X for Unix Geeks, for which we had help from a number of folks. Thanks to:

  • The folks at Apple, for technical review and handholding in so many tough spots!

  • Erik Ray, for some early feedback and pointers to areas of library linking pain.

  • Simon St.Laurent, for feedback on early drafts and for prodding us toward more Fink coverage.

  • Chris Stone, for tech review and helpful comments on the Terminal application.

  • Tim O’Reilly, for deep technical and editorial help.

  • Brett McLaughlin, for lots of great technical comments as well as helpful editorial ones.

  • Brian Aker, for detailed technical review and feedback on Unixy details.

  • Chuck Toporek, for editing, tech review, and more.

  • Elaine Ashton and Jarkko Hietaniemi, for deeply detailed technical review and help steering the book in a great direction.

  • Steven Champeon, for detailed technical review and help on Open Firmware and the boot process.

  • Simon Cozens, for technical review and for pushing us toward including an example of how to build a Fink package.

  • Wilfredo Sanchez, for an immense amount of detail on everything, and for showing us the right way to do a startup script under Jaguar. His feedback touched nearly every aspect of the book, and without it there would have been gaping holes and major errors.

  • Andy Lester, Chris Stone, and James Duncan Davidson, for reviewing parts of the book and pointing out spots that needed touching up.

Acknowledgments from Brian Jepson

Thanks to Nathan Torkington, Rael Dornfest, and Chuck Toporek for helping shape and launch the previous editions of this book, and to Ernie Rothman and Rich Rosen for making it a reality with me. Thanks also to Charles Stephen Edge, Jr., for his helpful tech review of the manuscript. A big thanks to Isabel Kunkle, our editor, who helped us launch this new edition, keep it on track, and get it into your hands. Thanks also to readers of the previous edition who wrote to us asking for a new edition. Your encouragement means a lot!

I’d especially like to thank my wife, Joan, and my stepsons, Seiji and Yeuhi, for their support and encouragement through my late-night and weekend writing sessions, and for their patience throughout the unusual experiments I inflicted upon the home network and various computers during the writing and research of this book.

Acknowledgments from Ernest E. Rothman

I would first like to thank Brian Jepson, who conceived this book and was generous enough to invite me to participate in its development, and Rich Rosen, for joining us first as a technical reviewer and later as a coauthor. I would like to express my gratitude to Charles Stephen Edge, Jr., for his many useful comments as technical reviewer, and to our editor Isabel Kunkle, for editing, encouragement, patience, and kindness. I am also grateful to the visionary folks at Apple, Inc., for producing and constantly improving Mac OS X, and to the developers who spend a great deal of time writing applications and posting helpful insights on newsgroups, mailing lists, websites, and blogs. Finally, I am very grateful to my lovely wife, Kim, for her love, patience, and encouragement, and to my Newfoundland dogs, Max Bear and Joseph, for their love and patience. Both Max and Joseph were at my side for most of the time that I worked on the book, but my beloved Max (4/19/2002–5/5/2008) passed away suddenly before its completion. He will be forever in my heart.

Acknowledgments from Rich Rosen

First, my thanks to Brian Jepson and Ernie Rothman for giving me this opportunity to work with them on this book. Thanks also to Isabel Kunkle, for providing all sorts of help and guidance throughout this process, and to Charles Stephen Edge, Jr., for keeping us honest and making sure everything we said made sense.

On a personal note, my gratitude goes out to Leon Shklar, for providing me with so many great opportunities at the most opportune times, and to Dave Makower, for his steadfast friendship and his wealth of Mac knowledge. Likewise, I’m grateful to Igor Novgorodtsev for allowing me to borrow his copy of the Tiger edition of this book when I needed it.

Thanks to my parents, Arthur and Toby, for their lifelong support and encouragement. Most of all, I thank my wife, Celia, for nourishing my ears, my eyes, my heart, and my soul.

Get Mac OS X For Unix Geeks, 4th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.