Learning Unix for OS X Mountain Lion
Dave Taylor
Published by OReilly Media
Beijing Cambridge Farnham Kln Sebastopol Tokyo
Preface
Its been a long time since we went through the dramatic transition from Mac OS 9 to the more complicated and graphically rich world of OS X. Many of you reading this have never known a Mac interface that wasnt actually OS X (pronounce that oh-ess ten to sound cool). The biggest change when Apple switched operating systems was that every machine then gained multitasking and multiuser capabilities.
What you might not have realized, however, is that it was the underlying operating system itself that changed in the update to OS X, and that you now have a tremendously powerful OS that can run thousands of open source applications downloaded free from the Net, along with a command-line interface that makes even the most complex tasks a breeze.
If you want to learn the key phrases, beneath OS X lies an operating system called Unix (pronounced you-nicks): specifically, UC Berkeleys BSD Unix and the Mach kernel, a multiuser, multitasking operating system. Being multiuser means OS X allows multiple users to share the same system, each with their own settings, preferences, and separate area in the filesystems, secured from other users prying eyes. Being multitasking means OS X can easily run many different applications at the same time, and if one of those applications crashes or hangs, the entire system doesnt need to be rebooted. Instead, you just force quit the application thats causing the Spinning Beach Ball of Death (you know, when the mouse pointer turns into a spinning color wheel that just wont stop rotating) and either relaunch it or proceed with your work in other apps.
The fact that OS X has Unix under the hood doesnt matter to users who simply want to use its slick graphical interface to run their applications or manage their files. But it opens up a world of possibilities for users who want to dig a little deeper. The Unix command-line interface, which is accessible through the Terminal application ( /Applications/Utilities ), provides an enormous amount of power for intermediate and advanced users. Whats more, once youve learned to use Unix in OS X, youll also be able to use the command line in other versions of Unix, such as FreeBSD (from which OS X derives its Unix core) or even the hugely popular Linux.
This book is designed to teach Mac users the basics of Unix. Youll learn how to use the command line (which Unix users refer to as the shell ) and the filesystem, as well as some of Unixs most useful commands. Ill also give you a tour of some useful Unix commands that Apples team have written and include with every Mac systemutilities that let you really gain control over your system. Unix is a complex and powerful system, so I can only scratch the surface, but Ill also tell you how to deepen your Unix knowledge once youre ready for more.
Who This Book Is For
This book is for savvy Mac users who are comfortable in their current world (the Finder and other GUI applications) but also want to learn more about the Power of Unix that Apple keeps talking about. Here, youll learn all the basic commands you need to get started with Unix. Rather than weighing you down with lots of details, I want to help you get comfortable in the Unix environment as soon as possible. So, I cover each commands most useful features instead of describing all its options in detail. And let me tell you, Unix has thousands of commands with millions of options. Its very powerful! But fortunately, its just as powerful and helpful even if you just focus on a core subset and gradually learn more as you need additional power and capabilities.
Who This Book Isnt For
If youre seeking a book that talks about how to build Mac software applications, this isnt it (although its quite helpful for developers to have a firm grasp of Unix essentials, because you never know when youre going to need them). And if youre a complete beginner and are occasionally stymied by where the second mouse button has gone, you might be better off putting this book on the shelf until youre more comfortable with your Macintosh.
Finally, if you live and breathe Unix every day, this book is probably too basic for you. I also dont cover either Unix system administration or Mac system administration from the command line. For example, if you already know what a PID is and how to kill a program, this book is probably beneath your skill level. But if you dont know what those terms mean, or if youre somewhere in between, youve found the right book!
A Brief History of Unix
The Macintosh started out with a single-tasking operating system that allowed simple switching between applications through an application called the MultiFinder. More recent versions of the Mac OS have supported multiple applications running simultaneously, but it wasnt until the landmark release of OS X that true multitasking arrived in the Macintosh world. With OS X, Macintosh applications run in separate memory areas; the Mac is a true multiuser system that also includes proper file-level security.
To accomplish these improvements, OS X made the jump from a proprietary underlying operating environment to Unix. OS X is built on top of Darwin, a version of Unix based on BSD 4.4 Lite, FreeBSD, NetBSD, and the Mach microkernel.
Unix itself was invented more than 40 years ago for scientific and professional users who wanted a very powerful and flexible OS. It has evolved since then through a remarkably circuitous path, with stops at Bell Telephone Labs, UC Berkeley, and research centers in Australia and Europe, and also received some funding from the US Department of Defense Advanced Research Projects Agency (DARPA). Because Unix was designed by experts for experts (or geeks, if you prefer), it can be a bit overwhelming at first. But after you get the basics (from this book!), youll start to appreciate some of the reasons to use Unix. For example:
It comes with a huge number of powerful programs, and you can get many others for free on the Internet. (The Fink project, available from SourceForgehttp://fink.sourceforge.netbrings many open source packages to OS X.) You can thus do much more at a much lower cost.
Unix is pretty much the same, regardless of whether youre using it on OS X, FreeBSD, or Linux, or even in tiny embedded systems or on a giant supercomputer. After you read this book, youll not only know how to harness the power of Unix, but youll also be ready to use many other kinds of Unix-based computers without having to learn new commands for each one.
Versions of Unix
There are several versions of Unix. Some past and present commercial versions include Solaris, AIX, and HP/UX. Freely available versions include Linux, NetBSD, OpenBSD, and FreeBSD. Darwin, the free Unix version underneath OS X, was built by grafting an advanced version called Mach onto BSD, with a light sprinkling of Apple magic for the Aqua interface.
Although GUIs and advanced features differ among Unix systems, you should be able to use much of what you learn from this introductory handbook on any system. Dont worry too much about whats from what version of Unix. Just as English borrows words from French, German, Japanese, Italian, and even Hebrew, OS Xs Unix borrows commands from many different versions of Unixand you can use them all without paying attention to their origins.
From time to time, I explain features of Unix on other systems. Knowing the differences can help you if you ever want to use another type of Unix system. When I write Unix in this book, I mean Unix and its versions, unless I specifically mention a particular version.