Last week, Take Control Books published a brand new, thoroughly revamped second edition of my book Take Control of the Mac Command Line with Terminal, with over 50 pages of new material. If I do say so myself, it’s one of the best resources available for a Mac user to learn about OS X’s Unix underpinnings and how to do useful things on the command line.
This is not a book just for computer geeks. Far from it; it’s a book for anyone who wants to learn a new skill that gives you far more control over the way your Mac behaves than you would otherwise have. It may sound like a complex topic, but that’s why I wrote the book—to show you how simple it can be. I had lots of fun writing about the command line (which I use every single day), and I hope my enthusiasm shows in the book.
But isn’t the command line kind of anachronistic? I prefer to think of it as an old but useful tool that continues to work well alongside other, newer but more specialized tools.
The first computer I owned was a Commodore VIC-20 (the fancier Commodore 64 was too expensive for my family). That computer, like the TRS-80s I’d used in high school and the Apple IIs and IBM PCs I’d use in college, had no mouse. You told it what to do by typing commands on the keyboard. By today’s standards, the text-based interfaces of these old systems seem quaint if not downright backward. Modern computers have graphical interfaces that we manipulate with physical gestures of one sort or another, or by speech. Those interfaces seem easier to use, and sometimes they are—but it depends on what you mean by “easy.”
A task I need to do on a regular basis is to rename certain files so that they follow a particular pattern. The pattern I need is the date (in YYYY-MM-DD format), a hyphen, and the file’s title (which is found in one of its first few lines) converted to lowercase, with spaces and punctuation removed and hyphens between the words. Something along these lines:
I could do all that manually, of course. But it’s irritating, tedious, and error-prone work—exactly the kind of work my Mac should be able to do for me! So, using the command line, I wrote a little shell script that does all this for me. (To make it easier still, I embedded that script in a Keyboard Maestro macro so I can activate it anywhere with just a keystroke.)
My point is: A keystroke is simpler than a manual renaming process I have to repeat over and over again. And the command line lets me do that in a way the Finder and other graphical tools do not. It makes my life easier.
Here’s another example from the book. Suppose you’re trying to eject a volume from your Mac—an external hard drive, a network volume, or whatever—and you keep getting an error message saying the volume is in use. OK…what are you supposed to do with that information? Just wait and hope it sorts itself out eventually? Maybe if you knew what was using it, you could do something about it, but the Finder doesn’t tell you. So enter the following in Terminal, substituting for VolumeName the name of the volume you can’t unmount:
lsof | grep /Volumes/VolumeName
You’ll get a tidy list of any apps or other processes using that volume, and then you can quit whatever is holding things up. Piece of cake. And a lot simpler than guessing or randomly quitting apps, hoping that you’ll stumble on the right one.
The book has dozens of other little “recipes” like this. It teaches you all the basics of using the Terminal utility, the most important commands you’ll need to use frequently, and how to progress to more advanced skills if you’re interested in doing so. I hope you find it helpful!