|Home Catalog FAQ||Log In|
Save 20% and recruit more robots when you buy with Take Control of Automating Your Mac for only $24!
Save 30% when you build your own bundle of three or more books, including Take Control of...
(30% discount overrides other coupons and is calculated on the first screen of our cart.)
Take Control of the Mac Command Line with Terminal, Second Edition
Learn how to unleash your inner Unix geek!
If you’ve ever thought you should learn to use the Unix command line that underlies Mac OS X, or felt at sea when typing commands into Terminal, Joe Kissell is here to help! With this 167-page ebook, you’ll become comfortable working on the Mac’s command line, starting with the fundamentals and adding more advanced topics as your knowledge increases.
Joe includes numerous real-life “recipes” for tasks that are best done from the command line, as well as directions for working with permissions, carrying out grep-based searches, creating shell scripts, and installing Unix software.
"I found the answers to many questions I had in your book, and I enjoyed reading it. I am definitely more confident now in facing the Mac command line. Thank you for the time and art that you spent to create such a clarifying text."
—Mona Hosseini, grad student in Genomic Medicine and Statistics at the University of Oxford
The book begins by teaching you these core concepts:
Next, it’s on to the command line, where you’ll learn:
You’ll extend your skills as you discover how to:
Questions answered include:
"Very good! A pleasure to read, the right balance of coverage and clarity."
Finally, to help you put it all together, the book showcases over 50 real-world “recipes” that combine commands to perform useful tasks, such as listing users who’ve logged in recently, copying text from Quick Look, using a separate FileVault password, figuring out why a disk won’t eject, copying the source code of a Web page, determining which apps have open connections to the Internet, flushing the DNS cache, finding out why a Mac won’t sleep, sending an SMS message, and deleting stubborn items from the Trash.
iPad & Kindle
About the Author
Joe Kissell has written many books about the Mac, including many popular Take Control ebooks. He's also a contributing editor of TidBITS and a senior contributor to Macworld, and previously spent 10 years in the Mac software industry.
Table of Contents
Read Me First
Welcome to Take Control of the Mac Command Line with Terminal, Second Edition! This book introduces you to Mac OS X’s command line environment, teaching you how to use the Terminal utility to accomplish useful, interesting tasks that are either difficult or impossible to perform in the graphical interface. The book was written by Joe Kissell, edited by Geoff Duncan, and published by TidBITS Publishing Inc.
Back when I began using computers, in the early 1980s, user interfaces were pretty primitive. A computer usually came with only a keyboard for input—mice were a novelty that hadn’t caught on yet. To get your computer to do something, you typed a command, waited for some result, and then typed another command. There simply was no concept of pointing and clicking to make things happen.
When I finally switched from DOS to the Mac (without ever going through a Windows phase, I should mention!), I was thrilled that I could do my work without having to memorize lists of commands, consult manuals constantly, or guess at how to accomplish something. Everything was right there on the screen, just a click away. It was simpler—not in the sense of being less powerful, but in the sense of requiring less effort to access the same amount of power. Like most everyone else, I fell instantly in love with graphical interfaces.
Fast forward a couple of decades, and I find myself faced with some mundane task, such as deleting a file that refuses to disappear from the Trash or changing an obscure system preference. After wasting time puzzling over how to accomplish my task—and perhaps doing some Web searches—I discover that Mac OS X’s graphical interface does not, in fact, offer any built-in way to do what I want. So I have to hunt on the Internet for an application that seems to do what I want, download it, install it, and run it (and perhaps pay for it, too), all so that I can accomplish a task with my mouse that would have taken me 5 seconds in DOS 30 years ago.
That’s not simple.
I’m a Mac user because I don’t have time to waste. I don’t want my computer to put barriers between me and my work. I want easier ways to do things instead of harder ways. Ironically, Mac OS X’s beautiful graphical interface, with all its menus, icons, and buttons, doesn’t always provide the easiest way to do something, and in some cases it doesn’t even provide a hard way. The cost of elegance and simplicity is sometimes a lack of flexibility.
Luckily, Mac OS X isn’t restricted to the graphical realm of windows and icons. It has another whole interface that lets you accomplish many tasks that would otherwise be difficult, or even impossible. This other way of using Mac OS X looks strikingly like those DOS screens from the 1980s: it’s a command-line interface, in which input is done with the keyboard, and the output is sent to the screen in plain text.
The usual way of getting to this alternative interface (though there are others) is to use a program called Terminal, located in the Utilities folder inside your Applications folder. It’s a simple program that doesn’t appear to do much at first glance—it displays a window with a little bit of text in it. But Terminal is in fact the gateway to vast power.
If you read TidBITS, Take Control books, Macworld, or any of the numerous other Mac publications, you’ve undoubtedly seen tips from time to time that begin, “Open Terminal and type in the following…”. Many Mac users find that sort of thing intimidating. What do I click on? How do I find my way around? How do I stop something I’ve started? Without the visual cues of a graphical interface, lots of people get stuck staring at that blank window.
If you’re one of those people, this book is for you. It’s also for people who know a little bit about the command line but don’t fully understand what they can do, how to get around, and how to stay out of trouble. By the time you’re finished reading this book and trying out the examples I give, you should be comfortable interacting with your Mac by way of the command line, ready to confidently use Terminal whenever the need arises.
It’s not scary. It’s not hard. It’s just different. And don’t worry—I’ll be with you every step of the way!
Much of this book is concerned with teaching you the skills and basic commands you must know in order to accomplish genuinely useful things later on. If you feel that it’s a bit boring or irrelevant to learn how to list files or change directories, remember: it’s all about the end result. You learn the fundamentals of baking not because measuring flour or preheating an oven is intrinsically interesting, but because you need to know how to do those things in order to end up with cookies. And let me tell you, the cookies make it all worthwhile!
Speaking of food—my all-purpose metaphor—this book doesn’t only provide information on individual ingredients and techniques. The last chapter is full of terrific, simple command-line recipes that put all this power to good use while giving you a taste of some advanced capabilities I don’t explore in detail. Among other things, you’ll learn:
How to figure out what’s preventing a disk from disconnecting (unmounting or ejecting)
How to tell which applications are currently accessing the Internet
How to rename lots of files at once, even if you’re not running Yosemite
How to change a number of hidden preferences
How to understand and change file permissions
How to automate command-line activities with scripts
Astute readers may note that some of these tasks can be accomplished with third-party utilities. That’s true, but the command line is infinitely more flexible—and Terminal is free!
I should be clear, however, that this book won’t turn you into a command-line expert. I would need thousands of pages to describe everything you can accomplish with the command line. Instead, my goal is to cover the basics and get you up to a moderate level of familiarity and competence. And, based on feedback from the first edition of this book, I’ve expanded the scope of this revised second edition to include a number of topics that are a bit more advanced.
Most of my examples work with any version of Mac OS X from 10.6 Snow Leopard on, although many also apply to earlier versions of Mac OS X. A few techniques require 10.9 Mavericks or 10.10 Yosemite; I point out those out as we go along.
This book is mostly linear—later sections tend to build on earlier sections. For that reason, I strongly recommend starting from the beginning and working through the book in order (perhaps skimming lightly over any sections that explain already familiar concepts). You can use the items in the final chapter, Command-Line Recipes, at any time, but they’ll make more sense if you understand all the basics presented earlier in the book.
Learn about the command line and its terminology; see Understand Basic Command-Line Concepts.
Become familiar with the most common tool for accessing the command line; see Get to Know (and Customize) Terminal.
Navigate using the command line; see Look Around.
Create, delete, and modify files and directories; see Work with Files and Directories.
Run or stop programs and scripts; see Work with Programs.
Make your command-line environment work more efficiently; see Customize Your Profile.
Integrate the command line and Mac OS X’s graphical interface; see Bring the Command Line into the Real World.
Use the command line to control another Mac; see Log In to Another Computer.
Learn about users, groups, permissions, and the infamous
sudo command; see Work with Permissions.
Learn Advanced Techniques such as piping and redirecting data, using the
grep search tool, and adding logic to your shell scripts.
Go beyond what’s built into Mac OS X by downloading third-party command-line programs; see Install New Software.
This revised and expanded second edition brings the book up to date with OS X 10.10 Yosemite (while maintaining compatibility all the way back to 10.6 Snow Leopard) and adds material that’s more advanced than what was in the first edition, enabling you to go further, do more in Terminal, and enhance your command-line skills.
The most significant changes include:
Refreshed the text with many small changes and updated screenshots to accommodate changes in the latest versions of OS X
Added new sidebars about Using a Mouse in Terminal (in the chapter Get to Know (and Customize) Terminal) and Finding Text in the Terminal Window (in the chapter Look Around)
In the chapter Work with Files and Directories, added a new topic, Use Symbolic Links, and sidebars about Running Multiple Programs on One Line and Running Shell Scripts outside the Shell
Included a fun tip about using emoji in your prompt, in Change Your Prompt
Expanded the discussion of how to Open the Current Folder in Terminal to include the use of services in Mavericks and later
In the Log In to Another Computer chapter, added a topic about how to Transfer Files with sftp or scp
Renamed the chapter formerly called “Venture a Little Deeper” to Work with Permissions, which is more accurate and descriptive, and added a topic called Use the chmod Absolute Mode
Added two entirely new chapters for more-advanced readers: Learn Advanced Techniques, which covers piping and redirecting, grep, and adding logic to shell scripts; and Install New Software, which discusses Command Line Tools for Xcode, downloading and installing Unix software from scratch, and using package managers such as Homebrew and MacPorts
In the Command-Line Recipes chapter, removed 6 obsolete recipes that no longer function in Yosemite or Mavericks and added 18 new ones (for a net gain of 12)
Expanded several of the existing recipes with more details
Version 1.1 is a minor update intended primarily for compatibility with versions of Mac OS X released since the book was first published (10.6 Snow Leopard, 10.7 Lion, and 10.8 Mountain Lion), as well as to correct a few small errors and broken URLs, and to adopt the latest Take Control formatting. I also made the following small adjustments:
Most of the examples in this book work with any version of Mac OS X up through 10.10 Yosemite, but a few of them require Mac OS X 10.6 Snow Leopard or newer. If you’re using 10.4 Tiger or earlier, you’ll notice that the Terminal application isn’t identical—it omits tabs and some other customization options—but mostly works the same. When the book was last updated, it was freshened to include
There are lots of great ways to read our ebooks on these devices. For more details, please read our latest Device Advice.
Feel free to ask us if you have a question about this title!
How could we not publish such kind words? If you'd like to send us your comments (good or bad, though we hope they're all good), just click the Feedback link on the cover of your copy of the ebook. Be sure to let us know if we can publish your comment. Thanks!
I purchased this book a while back, just in case I needed to refresh Unix skills. However, the “tyranny of the immediate” (stuff we have to do NOW) kept me from doing much in terminal. However, in past couple days, I actually NEEDED to do some work in Terminal. Thus, I went through your whole book. It reminded me of a lot of things I had forgotten from 15 years ago, and presented some that I never knew. Thanks for this work, it is both informative and readily comprehensible.
I just wanted to say thank you. I expected to slog through the book and not derive a lot of pleasure out of it. I was very wrong. I almost worked through it all in one sitting, and I now find myself enjoying working in the command line! I never imagined this would end up being the case.
April 24, 2015 -- We have no specific plans for future updates.
—Tonya J Engst
May 13, 2015 --
Chuck Joiner and Joe Kissell sit down to discuss Joe’s latest edition of his guide to the Mac command line on MacVoices. Together they
ls the changes Joe made to the book to bring it current with Terminal in Yosemite, and
man up to the challenge of explaining this essential but technical tool to typical Mac users. (By the way, if you don’t know what
man mean, you need to read the book!)
—Michael E. Cohen
August 16, 2012 --
Safari 6.0, which Apple released into the wild at the same time it did Mountain Lion, lacks the preference option, present in earlier versions, for setting the default proportional font and fixed-width fonts. Fortunately, you can still set them using a series of
defaults commands in Terminal. To find out how, see the TidBITS article Fix Your Fonts in Safari 6.
—Michael E. Cohen
Visit our catalog to see all the other books we publish!
Teach classes? Check out our discounted class copy pricing!