Quantcast
The video player requires Flash 8 Player or later. Please download the latest Flash Player.


Maclife Hottest Articles
Thumbnail
FEATURE
100 Snow Leopard Tips, Tricks, and Features
Browser
FEATURE
OS X Browser Speed Wars: May the Fastest App Win
iTunes History
FEATURE
The Complete iTunes History -- SoundJam MP to iTunes 9
iTunes Tips
FEATURE
iTunes 9 Tips and Tricks - Solve the Mysteries of the New iTunes
25 Terminal Tips Every Mac User Should Know
Posted 12/11/2008 at 12:40:29pm | by Johnathon Williams

terminalFrom customizing your Mac’s secret system preferences to remotely controlling another Mac or manipulating text files in a handful of sly ways, the terminal utility is more than just a Mac geek’s home base. It’s a place where, with a few expert tricks, all Mac users can feel right at home.

 


If there’s a more neglected or misunderstood Mac utility than the Terminal, OS X’s built-in command-line app, we’ve yet to find it. In an age where Apple’s $200 smart phone offers the most intuitive graphical user interface the world has ever seen, turning to a text-only command-line window can seem stubbornly retro, reminding us of audiophiles who vociferously insist that vinyl records sound better than music CDs. But there are plenty of reasons for using the command line beyond mere nostalgia: speed, flexibility, and familiarity with OS fundamentals, to name a few. We’ve collected 25 Terminal-based solutions for common desktop issues, because knowing these tricks is an invaluable addition to any Mac user’s toolbox. And while there is no reason to abandon the Finder, think of mastering the Terminal as learning to drive a car with a manual transmission—once you can drive a stick, you can drive anything.

 

The first thing to know about the Terminal is how to launch it, which you do by 
going to \Applications\Utilities\Terminal. Also, you’re no longer in graphical user-interface land: Most of what you’ll do in the Terminal is enter specific text strings, then press Return to execute them. When you see generic references like name-of-file or path-to-file throughout this article, replace that text with your file name or path.

 

1.  Handy Terminal Pointers

>    Only text commands are accepted--you won’t use your mouse much within the terminal, with a few exceptions.
>    Execute commands by pressing Return.
>    Every keystroke matters, including spaces and special symbols.
>    Interrupt any running command by pressing Control-Z.
>    Recall previously entered commands without retyping them by pressing the up arrow.
>    Curious about a new command? Type man name-of-the-command, then press Return to read its instruction manual. For instance, man SSH will produce the manual for SSH.
>    For a list of all commands available in the Terminal, hold down Escape, then press Y when prompted.
>    Page down through multipage results by pressing the space bar.
>    For commands that require the path to a file or folder, save yourself some typing by dragging and dropping the file or folder at the end of the command. The Terminal will automatically copy the dropped item’s path and name.

 

2.  Know Your Way Around

By default, the Terminal targets your Home directory (folders are called directories in Terminal-speak). You can move to different directories by executing the command cd path-to-directory. If you get lost, type cd ~ to return to your Home directory. View a list of all files in the Terminal’s current directory by executing ls

 

3. Anatomy Of A Terminal Command


screen shot of terminal command

Unlike the sentences you were forced to diagram in sophomore English, Terminal commands only have three parts: the command, which calls a specific command-line utility; the options, which modify the command’s output; and the argument, which is typically the website, file, or other resource that the command will be operating on.

 

4. Get Comfortable in Your Shell

The Terminal app is Apple’s implementation of a traditional Unix command-line environment, also called a shell. Keep in mind, though, that Unix shells come in many different flavors. OS 10.5 (Leopard), for instance, uses the Bash shell by default. If this article inspires you to Google even more command-line tricks, remember that some command-line utilities are shell-specific, meaning that what works in Tcsh on that helpful blogger’s Linux box might not work in Bash on your Mac.

 

defaults

When it comes to customizing the look and feel of your Mac, the options listed in System Preferences only scratch the surface. Hiding throughout the OS are dozens of hidden preferences that can only be changed through the defaults command. Too many exist to list them all here, so we’ve compiled our five favorites. Always remember to quit an application before modifying its defaults. You can reset any of these commands by replacing TRUE with FALSE and executing it again.

 

5. Make All Links In Safari Open As New Tabs


Screen shot of Safari Window
New windows, baaad. New tabs, gooood.

In general, Safari’s tab controls are wonderful, but one failing drives us crazy: Certain links are allowed to override your preference for opening new webpages in tabs, essentially forcing the application to open a new window. To prevent this in the future, execute this command: defaults write com.apple.Safari TargetedClicksCreateTabs -bool TRUE.


6. Force Mail To Display All Messages As Plain Text


Screen shot of Mail in plain text
Even those annoying bank statements appear in plain text, thanks to the magic of defaults.

Few things are more irritating than that office mate who just discovered how to make colored fonts and add funny graphics in his email program. With the exception of Mail’s attractive New Message templates, most heavily formatted messages are spam anyway, so make things easier on your eyes by forcing all messages to display as plain text by executing this command: defaults write com.apple.mail PreferPlainText -bool TRUE.

 

7. Show Hidden Files in The Finder


screen shot of hidden finder folders
The names of hidden files always begin with a period--keep that in mind before you delete or edit a file that doesn’t look familiar.

Believe it or not, the files you see listed on your Desktop in the Finder do not represent all of the files contained in your Desktop folder. In almost every folder, the OS hides system files that Apple considers too important for the likes of us to mess with (or too mundane for us to be bothered with). Now and again, though, it’s useful to view these files. To see the full contents of all folders in the Finder, execute  defaults write com.apple.finder AppleShowAllFiles TRUE.

 

8. Change The File Format For Screenshots


Screen shot changing image format of screen shots
PNG, or portable network graphics, is a file format that offers high image quality and small file sizes, but may not be opened by all image-editing software.

OS 10.5 saves screen captures as PNG files by default, but it can save them in a variety of formats, including PDF, JPG, and GIF, to name a few. Switch to your preferred format by executing defaults write com.apple.screencapture type file-extension, replacing file-extension with the three-letter abbreviation for your chosen format. For instance, to change the default format to PDF, you’d execute defaults write com.apple.screencapture type PDF.

 

9. Disable the Dashboard


screen shot of Dashboard app
When the Dashboard appears on our Desktop, it’s usually because we missed the delete key and hit F12 instead.

We’ve always liked the Dashboard in theory--on occasion, we’ve even downloaded widgets for it. Unfortunately, we never get around to using them, and our aging Mac laptop could use the extra RAM to run real apps. If you’re in the same boat, free up some system memory by terminating the Dashboard with two quick Terminal commands. First, set its default to Off by executing defaults write com.apple.dashboard mcx-disabled -boolean YES. Second, kill and restart the Dashboard and Dock with this command: killall Dock.

 

Next Mac Security Terminal Style

COMMENTS
avatarGreat article

And lest some users are thinking this is too uber-geeky for mere mortals such as themselves, it's worth mentioning that highlighted text from any text document can be dragged right into an open terminal window. If anyone were uncomfortable typing directly in Terminal, they could save a document of their favorite commands and just drag 'em over. Easy.

Login or register to post comments
avatarA very timely article!

What a very timely article (for me at least!). I was just looking into this... It is always a hassle setting up a new computer, it would be nice if I could just run a script that would configure some/most of my system for me. I've found some commands that looked promising but ran into a few road blocks... I went to my local Apple Store and there the Genius told me that they didn't do Unix! That sucks. Here what I have so far:I randefaults read com.apple.finder DesktopViewOptions{ IconViewOptions = { ArrangeBy = none; BackgroundFlags = 0; BackgroundType = DefB; FontSize = 12; GridSpacing = 73; IconSize = 48; PropertiesLocation = botm; ShowPreviewIcon = 1; ViewMoreInfo = 0; };}I could reset the icon size or the font size or the grid spacing but not all three of them at once by using one of the following:defaults write com.apple.finder DesktopViewOptions -dict IconSize -integer 32;defaults write com.apple.finder DesktopViewOptions -dict FontSize -integer 11;defaults write com.apple.finder DesktopViewOptions -dict GridSpacing -integer 40;killall FinderI'd like to do something along the lines of:defaults write com.apple.finder DesktopViewOptions { IconViewOptions = { FontSize = 11; GridSpacing = 40; IconSize = 32; };}But this does not work. Any ideas?

Login or register to post comments
avatarA very timely article!!

What a very timely article (for me at least!). I was just looking into this... It is always a hassle setting up a new computer, it would be nice if I could just run a script that would configure some/most of my system for me. I've found some commands that looked promising but ran into a few road blocks... I went to my local Apple Store and there the Genius told me that they didn't do Unix! That sucks. Here what I have so far:I randefaults read com.apple.finder DesktopViewOptions{ IconViewOptions = { ArrangeBy = none; BackgroundFlags = 0; BackgroundType = DefB; FontSize = 12; GridSpacing = 73; IconSize = 48; PropertiesLocation = botm; ShowPreviewIcon = 1; ViewMoreInfo = 0; };}I could reset the icon size or the font size or the grid spacing but not all three of them at once by using one of the following:defaults write com.apple.finder DesktopViewOptions -dict IconSize -integer 32;defaults write com.apple.finder DesktopViewOptions -dict FontSize -integer 11;defaults write com.apple.finder DesktopViewOptions -dict GridSpacing -integer 40;killall FinderI'd like to do something along the lines of:defaults write com.apple.finder DesktopViewOptions { IconViewOptions = { FontSize = 11; GridSpacing = 40; IconSize = 32; };}But this does not work. Any ideas?

Login or register to post comments
avatarFormat for comment suck...

How do you turn off the reformatting?

Login or register to post comments
avatarIf you're using TextEdit...

then click Format > Make Plain Text or press Shift-Command-T.  This will strip the document of all formatting (e.g. font, color, italicize, etc.).

Login or register to post comments
avatarVi(m) customization

i'd love to see some 411 on customizing Vi(m) on the mac. for when i want to edit a file without opening a bloated text editor (dreamweaver).

b

Login or register to post comments
avatarSome good info, but...

I'm relieved to see you corrected the "key" on the image in tip #3 as printed in this issue of the magazine, which was grossly incorrect. Now just change #15 to use Ctrl-C to stop ping, instead of Ctrl-Z (not Command-Z) which just suspends a command instead of stopping it. Yes, the picture says "Stopped", but it's still running. Type "fg" after hitting Ctrl-Z and you'll be taken right back to the ping. Same Ctrl-Z foolishness on #17.

Login or register to post comments
avatarVery good tips to follow. I

Very good tips to follow. I am sure that a lot of people didn't know about these things when it comes to using Mac. I am grateful that you thought about us and put this information in this post for us.

______

Royal Caribbean Cruises

Login or register to post comments
avatarCtrl-Z

Hi,Just a quick note about Ctrl-Z. When you use Ctrl-Z to stop a job or process that is running, it doesn't "kill" that process, just interrupts it and makes it wait. This is actually quite handy at times, because you have some job control you can do afterward:1) run the "jobs" command to see a list of jobs you've got waiting.2) run the "fg %#" command to bring a command back to active from the jobs list (use the number instead of the pound symbol).3) run the "bg %#" command to let a job run in the background (great for calculations and tasks that don't have much output!).4) run the "kill %#" command to kill the job.Be sure to put the percent symbol before the jobs list number, especially with the kill command, otherwise, it will use the process id (run "ps auxw" to see a list of all processes).Cheers,Andrew

Login or register to post comments
avatarSSH How do you find IP addresses of networked Macs using termina

I enjoy these types of articles. Keep them coming.

Re: SSH
So now that I'm ready to ssh into another Mac (or pc) on my home network, how do I discover their IP addresses without getting up out of my chair? I know that I can walk around the house and look in the Network Prefs to learn the IP address but I want to do it remotely. In my old Linksys router there was a panel in the web admin control screen showing the IP addresses of all the clients on my network. I don't see this in the Airport Utility for my new Time Capsule.

Is there a way to use the terminal to do this?

Matt

Login or register to post comments
avatarFining IP addresses

You can use a little app called Flame that will list all the IP addresses in your network.

Login or register to post comments
avatarQuestion about Secure Erase of Free Space on my HD

I executed this command "diskutil secureErase freespace 3 /Volumes/Macintosh\ HD" and it's running the erase but it seems to have doubled the contents of the HD, if only temporarily. Is this normal cause there's like Zero room left on my HD? Will it go away after the erase is complete? I just backed up w/ time machine on an external so I'm not super worried, but I'd just like to know what's going on.

Thanks
Nick

Login or register to post comments
avatarFollow up?

How did this work out for you?  Space back to normal?

Login or register to post comments
avatarA few more tips!

This list is great, and it goes from beginning to much more advanced.

Try

sudo !!
This reexecutes the last command entered as root. Great for when you get pesky 'Permission Denied' errors

A mac exclusive! When you have a file in the finder that you want to do something with, you can just drag it into terminal and it will put the path (the file's location) to that file where your cursor is.

Having trouble deleting a large amount of stuff from trash or taking too long to do the 'preparing to delete' thing? Try:

sudo rm -rf /.Trashes/*
or
sudo rm -rf /Volumes/Secondary-hard-drive/.Trashes/*

If you forget to put the .Trashes in the command, you could end up deleting a significant amount of important stuff.

Login or register to post comments
avatarGood tips..

Guys always remember to quit an application before modifying its defaults.
herpes - lasik surgery

Login or register to post comments
avatarThose are some very good

Those are some very good tips that everyone should pay attention to.
Air Mattress Bed
Air Mattress Bed Frame
camping air mattress
air mattress beds

Login or register to post comments
avatarPermission Errors?

I am the only one using my MacBook Pro. I would like to know where Permission errors come from.

Login or register to post comments
avatarI am sure that a lot of

I am sure that a lot of people didn't know about these things when it comes to using Mac. I am grateful that you thought about us and put this information in this post for us.knee pain | pain relief

Login or register to post comments
avataromega watches

Every little chat Salon 1000 ah!replica watchYou are my best's buddy
35rfd

Login or register to post comments
avataromega watches

Were not smart, but also learn from others bald.omega watchesChing had no water to fish, one to the cheap is invincible.replica watchI left Dragon, White Tiger right shoulder tattooed Mickey Mouse.replica watchesEfforts should be made! ! For your Audi Dior me.nong

Login or register to post comments
avatarthank you ar..is

thank you ar..is niceR$#
شات صوتي, دردشه صوتيه, شات مصريه, شات دردشة دردشه دردشة موبايل شات دردشه

Login or register to post comments