Mac OS X: Time-Saving Terminal Tips

| TMO Quick Tip

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.

Comments

John Martellaro

Thank you Melissa!

Melissa Holt

You’re welcome, John! :D

davidneale

You can do lots of clever and useful things with Terminal, but you can do plenty of damage, too, with a simple typing error. Also, it’s not easy for the casual user to keep up with all the terminal commands ands their parameteres. A safer and easier option is provided for free by Clix: http://rixstep.com/4/0/clix/

webjprgm

You can do lots of clever and useful things with Terminal, but you can do plenty of damage, too, with a simple typing error. Also, it?s not easy for the casual user to keep up with all the terminal commands ands their parameteres. A safer and easier option is provided for free by Clix: http://rixstep.com/4/0/clix/

Hmm, an interesting tool (for anyone who doesn’t want to follow the link, it looks to me like a Terminal for beginners that tries to give suggestions and some GUI to terminal commands).

My method, though, is to use “man commandname” for any new command that I don’t know.  I can find commands to do just about anything via Google, then I read up on what the parts are to increase my vocab and make sure I’m not doing anything that actually COULD break the system.  Most commands won’t break the system with a simple typo but rather will give an error message.

Josh

Interesting article.  I knew about most of these, except the “Paste Escaped Text”. 

It’s too bad though.  Your use of the double underlined add linking (vibrant) has forced me to unsubscribe from your rss feed.  I’ll miss you guys.

Dave Hamilton

Interesting article.? I knew about most of these, except the ?Paste Escaped Text?.

I agree. I’ve been a long-time command-line jockey and had never heard of the “Paste Escaped Text” until today. Melissa, you rock. wink

It?s too bad though.? Your use of the double underlined add linking (vibrant) has forced me to unsubscribe from your rss feed.? I?ll miss you guys.

Sorry to hear that, Josh. Our content isn’t free, of course, and viewing our choice of ads are the way you pay for it (so that we can, in part, pay writers like Melissa for producing such excellent content). That said, I do completely understand and respect your need to take a stand where you feel necessary. We’ll miss you, too.

Melissa Holt

Aw, geez, Dave! Thanks. smile

ilikeimac

Cool article; “paste escaped text” is new to me as well.

My favorite time saver not yet mentioned is using the up- and down-arrows to browse command history and repeat recent commands. I also love using

!$ 

in place of retyping the last argument of the last command. For example, you could create a folder and then open it in the Finder by running

mkdir "My Secret Stash"
open !$ 
Melissa Holt

I also love using

!$ 

in place of retyping the last argument of the last command.

ilikeimac, you taught me something I did not know. I love that!

Log-in to comment