Why Use the Keyboard? (MacBook)

To begin benefiting from the UNIX underpinnings of Mac OS X, get used to doing things with the keyboard. Although mouse skills can be applied to UNIX, you’ll generally find performing UNIX functions faster and easier with the keyboard.

UNIX keyboarding is fast

Why on Earth would any red-blooded MacBook owner want to leave the comfort of the trackpad to use a keyboard? After all, the graphical user interface is what made the Macintosh great in the first place. With the Finder, you can navigate and manage the various files on your hard drive with a few clicks. This sounds simple enough, but for some tasks, using the keyboard can be just as fast, if not faster.
Suppose, for example, that you need to copy a file from somewhere on your hard drive to somewhere else on that same drive. To do so with the Finder, you must first open a Finder window (by clicking the Finder icon in the Dock or by double-clicking a drive icon on your Desktop). Then, by using a succession of trackpad clicks, you navigate to where the file that you wish to copy resides. Next, you might open another Finder window and navigate to the folder where you wish to copy the file. (Note that opening the second Finder window requires pressing 96+N or choosing FileONew Finder Window; clicking the Finder icon in the Dock doesn’t open a second Finder window.) Finally, you duplicate the original file and drag that copy to its intended destination.
Comparatively, by using the keyboard and the power of UNIX, you can accomplish the same task with a one-line command. For some tasks, your trackpad (or a USB mouse) is definitely the way to go, but you can perform some other tasks just as quickly, if not faster, with the keyboard. For the skinny on one-line commands, skip down to the upcoming section “Uncovering the Terminal.”


The UNIX keyboard is a powerful beast

So maybe you’re not an expert typist, and using the trackpad still sounds inviting. For many scenarios, you’d be correct in assuming that a “pointing thing” can handle the job just as quickly and easily as a bunch of commands that you have to memorize. Using the keyboard, however, offers some other distinct advantages over the trackpad. To allow you to control your computer from the keyboard, all UNIX operating systems offer the command line tool. With this tool, you can enter commands one line at a time: hence, its name. Mac OS X ships with the command line application, Terminal. You can find it here:

Applications/Utilities/Terminal

One shining feature of the command line is its efficiency. To wit: When you use a trackball or mouse, one click is equal to one command. When you use the command line, on the other hand, you aren’t limited to entering one command at a time; rather, you can combine commands into a kind of super-command (minus the silly cape, but with bulging muscles intact), with each command performing some action of the combined whole. By using the command line, you can string together a whole bunch of commands to do a very complex task.

For example, consider how many times you’d have to click in the Finder to do the following:

1. Find all files that begin with the letters MyDocument.
2. From this list of files, add a number to the beginning of the filename, indicating its size in kilobytes.
3. Save the names of all altered files to a text file.
By using the command line, you could accomplish all these tasks by typing only one super-command: that is, a collection of three simple commands combined to form one instruction. The built-in Terminal program that ships with Mac OS X Snow Leopard gives you everything that you need to start using the command line. I show you how in the section “Uncovering the Terminal,” later in this topic.
Delving further into super-commands isn’t for the faint-hearted; things get pretty ugly pretty quickly, and this topic can only show you the very beginning of the UNIX Yellow Brick Road. Therefore, if your thirst for UNIX dominance so compels you, I invite you to do a little independent study to bone up on the operating system. Pick up a copy of the great topic of lore entitled UNIX For topic, 5th Edition, written by John R. Levine and Margaret Levine Young (Wiley).

Go where no trackpad has gone before

The Finder is generally a helpful thing, but it makes many assumptions about how you work. One of these assumptions is that you don’t have any need to handle some of the files on your hard drive. As I mention in Topic III, topic 6, Mac OS X ships with its system files marked Off Limits, and I generally agree with that policy (which keeps anyone from screwing up the delicate innards of Mac OS X). To secure your system files, Apple purposely hides some files from view.
But what road do you take if you actually need to view or modify those system files? Yep, you guessed it: The command line comes to the rescue! You can use the command line to peer inside every nook and cranny of your MacBook’s vast directory structure on your hard drive. It also has the power to edit files that aren’t normally accessible to you. With the command line, you can pretend to be other users — even users with more permissions. By temporarily acting as another more powerful user, you can perform actions with the command line that would be impossible in the Finder. (Just remember to make sure that you know exactly what you’re doing, or you’re working with an Apple technical support person — a wrong move, and it’ll be time for an Ominous Chord.)
tmp116-6_thumb

Automate to elevate

If all these benefits are beginning to excite you, hold on to your socks! Not only can you perform complex commands with the command line, you can go even one step further: automation. If you find yourself using the same set of commands more than once, you’re a likely candidate for using automation to save time. Instead of typing the list of commands each time, you can save them to a text file and execute the entire file with only one command. Now that’s power, right up there with the dynamic duo of AppleScript and Automator!
Of course, you probably don’t like doing housekeeping tasks while you’re busy on other things, so schedule that list of commands to run in the middle of the night while you’re fast asleep. UNIX lets you do that, too, using the launchd command.
Note that automation of UNIX commands is totally separate from automation of Mac OS X applications with AppleScript and Automator, which I cover in Topic IX, topic 2.

Remote control

“So,  the command line is the cat’s meow for efficiently accessing and working with files on my MacBook, and I can use it to automate many operations. Anything else?” I’m glad you asked! By using the command line, you can also send commands to another computer anywhere in the world (as long as you know the right login and password). After you log into another computer, you can use the same commands for the remote computer.
UNIX was created with multiple users in mind. Because computers used to be expensive (and honking huge machines to boot), UNIX was designed so that multiple users could remotely use the same machine simultaneously. In fact, if Mac OS X is your first encounter with UNIX, you might be surprised to know that many UNIX beginners of the past weren’t even in the same room, building, state, or even country as the computer that they were using.
tmp116-7_thumbNot only can you work with a computer that’s in a different physical location, but it’s also very fast to do so. Instead of the bandwidth hog that is the Internet, the command line is lean and mean. This permits you to use a remote computer nearly as fast as if it were sitting on the desk in front of you. (This is a great advantage for road warriors who need to tweak a Web or an e-mail server from a continent away.)

Next post:

Previous post: