Mac OS X: Time-Saving Terminal Tips

In this tip, we’re going to cover a few of my favorite time-savers for the Terminal, which lives in Applications > Utilities. I use Terminal almost every single day for one thing or another—it’s a great resource for troubleshooting problems, but it’s also an incredible program to help you understand more about what’s going on under the hood of your Mac.

I’m going to assume in this article that you guys have at least a passing familiarity with Terminal, so I may not go into a whole lot of detail about why you’d want to do certain things or what the terminology means. If you have any questions, though, feel free to ask in the comments, and either I’ll help you or one of our brilliant TMO members will. So let’s jump on in and get our feet wet, shall we? 

 

Command-Click the Title Bar

Just as in the Finder, you can hold down Command and click on the icon or the text in the title bar to get a hierarchical view of where you’ve navigated to in the file system. This, to me, is often faster than using pwd (present working directory), especially if I’m in the middle of something.

Save Windows as Group

If you often work with many windows at once, you can save their appearance, location, and even what directory they’ll open with, without you having to type in a gosh-darned thing afterward. To do this, enter and run the commands to change the windows to your preferred directories, adjust their size and location on your screen, and choose Window > Save Windows as Group.

After saving them out, you can invoke those windows either by choosing Window > Open Window Group or by setting them to launch when you start Terminal. Configure that by going to Terminal > Preferences > General and changing “On startup, open” to your new window group. You’re now a wizard, Harry.

Use Tab Completion

People who use the Terminal a lot live and die by Tab completion—I know it’s one of my favorite things ever. I like it more than I like coffee. 

Huh. So I really can lie with a straight face. 

Anyway, if you start typing the path to a folder, you can hit the Tab key to have Terminal fill in the rest for you.

Start typing, and then hit Tab…

 

…and you won’t have to type anymore. But why don’t I have an actual command in this image? Sigh.

 

If there aren’t any matches for what you’ve typed or if there’s more than one match, your Mac will make a complaining noise at you, and nothing will happen. If there is more than one match available, though, you can tap Tab again, and Terminal will show you your choices.

Drag Items from Finder

To quickly add the path to a file or a folder to a command, drag the item from the Finder and drop it onto your Terminal window. 

Paste Escaped Text

A quick explanation: If you’ve got a file or folder that has spaces or other special characters in its name (like “Old Photo of Mom!.jpg”), Terminal won’t understand what you’re asking it to do if you type in the filename exactly as it is. It assumes that a space should be interpreted as “move on to the next command or argument,” for example, which is obviously not what you’d want. To force Terminal to see the whole thing as a file name, you’ll have to escape those spaces and characters by adding in a backslash before each one, which’ll look like this:

Melissas-Laptop:~ melissa$ open /Users/melissa/Desktop/Old\ Photo\ of\ Mom\!.jpg

Typing that, however, can be a pain in the behind, so I always use Tab completion or dragging files in to avoid having to do it. What if you’ve copied the path from somewhere like Finder’s Go to Folder window, though? An easy way to save time is to paste it into Terminal by using the Edit > Paste Escaped Text menu item (or hit Control-Command-V).

That way, your path will be pasted in with the formatting already done. Let your Mac do the heavy lifting for you, I say. Just not literally.

Open the man Page or Related Pages

This one’s Lion-specific. What? You haven’t updated? For shame. Well, for the good little Apple fanboys and fangirls out there, what you can do in 10.7 is right- or Control-click on a command in the Terminal window and choose Open man Page from the contextual menu.

This, of course, takes the place of typing man [command] into Terminal when you’re looking to get instructional information. If you look in that same contextual menu, you’ll also see Search in man Pages, which is a simple way to look for commands relating to what you’re trying to do (it’s equivalent to doing apropos [keyword], for you Terminal junkies).

I’m sure this is apropos of something. Har har.

 

So now that we’ve walked through all of this, do you feel Terminal-ed out? I don’t. I’m ready to run a Terminal marathon! Look for all the man pages! Sudo all the things! Or maybe I’m ready to just go lie down and calm myself.