Advertisement
Terminal

10 Terminal Commands That Every Mac User Should Know

by

The Terminal in OS X is often, in my opinion anyway, an overlooked area of the operating system. Most newcomers to Macs look at it with fear, as the sight of anything code-related or advanced is enough to put them off for life. Fortunately, you don't have to be scared of Terminal and think of it as a feature just for the tech-minded. Knowing some basic Terminal commands can really enhance your experience of OS X. So, for all the beginners out there, here is my pick of the top 10 Terminal commands that every Mac user should know.


Before We Start...

Before we start tinkering around with it, it is probably worth taking a couple of minutes to tell you exactly what Terminal is (all in a non-technical sense, of course!).

Terminal OS X

Terminal.app running under OS X (Lion).

Terminal (officially called Terminal.app) is, strictly speaking, an emulator and works off most typical UNIX commands (OS X is a UNIX-based system, as opposed to Windows, which is NT-based). Unlike OS X, which has a graphical user interface (shortened to GUI), Terminal works off a text-based interface and all commands have to be typed in - this may be the reason why some people are scared off by it!

We won't go into massive detail on how Terminal works but it's best to learn the following three commands before we start this tutorial:

  • ls - list the contents of a particular directory
  • cd - change to another directory (as in DOS)
  • sudo - authenticate yourself a superuser to gain extra security privileges

Tip: >Be extra careful when using the sudo command. You will usually have to enter your OS X system password and any mistakes can permanently mess up your system for good. When in doubt, leave it out!

1. Disable Lion/Mountain Lion's Pop-up Accent Window

For people like me who write a lot of foreign accents then the pop-up accent window that came up when you hold down a letter for a longer period is extremely useful. But for those of you who want to write lots of repeat letters, it can be quite annoying. Use this simple trick to disable it:

defaults write -g ApplePressAndHoldEnabled -bool false

Hit Return then log out then back in again to see the changes. If you want to change back to the norm, then simply substitute false for true in the above.

2. Change the Default Backup Periods in Time Machine

By default, Time Machine backs up every hour when it's connected but this can be changed through Terminal. To do so, simply enter the following command:

sudo defaults write /System/Library/Launch Daemons/com.apple.backupd-auto StartInterval -int 1800

This makes Time Machine backup now every 30 minutes. To change it to what you want, simply replace the 1800 with the interval time in seconds (so 15 minutes would be 900 seconds, therefore enter 900). Also be aware that you are using a sudo command, so make sure that you've typed the command exactly right before you hit Enter (and you'll also be prompted to enter your system password).

3. Drag Dashboard Widgets onto the Desktop

I always forget that the Dashboard exists on my Mac. In fact, I hardly ever see a need for it. But I think that's mostly down to the fact that the widgets are hidden away inside the operating system. To be able to drag your Dashboard widgets onto your desktop, then enter the following command:

defaults write com.apple.dashboard devmode YES

You must log out then back in again and to drag a widget onto your desktop click and hold down on it then press F12, which dismisses it from the Dashboard and allows you to drop it onto the desktop. Your widgets now float above open applications, similar to the Gadgets on Windows 7.

To disable this feature, simply replace YES with NO in the above command. Again, you'll have to log out then back in again, unfortunately.

4. Disable Lion/Mountain Lion's Auto-restore Feature

This really bugged me when I first upgraded to Lion - the fact that when you open up something like Preview, all your recently accessed PDFs coming popping up in your face, even if you closed them down properly. Unfortunately there's no universal command to disable it across the entire OS so you'll have to do it for each individual program. If you want to disable it for Preview, then enter the following command:

defaults write com.apple.Preview NSQuitAlwaysKeepsWindows -bool false

QuickTime is another culprit in my eyes, again just enter:

defaults write com.apple.QuickTimePlayerX NSQuitAlwaysKeepsWindows -bool false

Make sure you quit and restart the apps to see the changes and if you want to reverse anything, simply substitute false for true (I'm sure you're getting the hang of this by now!).

5. Show Hidden Files in Finder

By default, the Finder in OS X hides some files away from view (mostly irrelevant ones) but if you want to see everything on your computer, then enter in the following command:

defaults write com.apple.finder AppleShowAllFiles TRUE

Again, substitute false for true to hide them again.

6. Change the File Format for Screenshots

Screenshots using the built-in shortcut for OS X are really useful but by default they are saved as PNG files. If you want to change this, then type in the following command:

defaults write com.apple.screencapture type file-extension

Replace file-extension with the three letter abbreviation of your desired file format, so for JPEG format simply enter JPG and for Acrobat PDF format, PDF. Terminal doesn't have to be difficult, does it?

7. Kill the Dashboard Altogether

Above, we went over the command to drop Dashboard widgets onto the desktop, but if you want to get rid of the Dashboard altogether (for example, if you're running an older Mac and have memory issues) then you can do via this simple Terminal command:

defaults write com.apple.dashboard mcx-disabled -boolean YES

Then, restart the Dock using the following command:

killall Dock

Et, voilà! No more Dashboard. If you find yourself afterwards lamenting after the good old days, replace YES with NO in the top command and repeat the process.

8. Securely Erase Free Space

When you delete files on your Mac, OS X still leaves fragments of the file all over the free space on your hard disk drive, until these are written over by new files. If you want to securely delete all the remaining fragments on a hard disk drive (for example if you're going to sell your Mac), then execute the following command:

diskutil secureErase freespace 3 /Volumes/name-of-drive

Replace /name-of-drive with the drive you want to erase. This command uses a special algorithm to wipe over each free area of space 35 times, far above the US Department of Defense's standard, which only requires 7 passes. Be aware though that this process can take days on larger drives.

On a side note, the command diskutil is a really useful one and allows you to manage local disks and volumes directly from the Terminal (a list of sample commands is given). Be aware, though, that most commands require root access.

9. Control Your Mac Remotely

Being able to control your Mac remotely via SSH, or secure shell, is far more advantageous than screen sharing as it uses less system resources and less bandwidth. The first thing you will have to do is enable Remote Login on your Mac, which you can do by heading over to System Preferences then Sharing then click on Remote Login.

SSH Mac
Be sure to enable Remote Login on your Mac before you start anything.

A little green light should come up, along with an IP address that you can use to log in via Terminal. The connection between the local Mac you're using and the remote one (i.e. your own one) is secure and encrypted, meaning that any data being transferred between the two cannot be intercepted.

To log into your Mac on another Mac, execute the command:

ssh -l username remote-address

Replace username with the username you'd use to log into OS X and remote-address with the IP address given to you in the Sharing pane. You can now control your Mac and execute Terminal commands remotely, a real plus.

10. Talking Mac!

And last but not least, if you want your Mac to speak to you, then simply use the say command, as in:

say Hello World!

The words will be spoken in your Mac's default voice but if you want to change this, then simply head over to System Preferences then either Dictation and Speech (on Mountain Lion) or simply Speech (on Lion). Here you can select different voices and download new ones from Apple's servers if you fancy. Another "useful" feature is the ability to convert an entire text file into speech, if you so fancy. Simply enter:

<strong>say -o audio.aiff -f FILENAME.txt</strong>

Replace FILENAME.txt with your own file. This will create a reading of your file as an AIFF file audio.aiff in Terminal's default directory.

Tip: Ever wondered if the Mac operating system is pronounced "OS ten" or "OS ex?" Your Mac knows the answer! Try typing "say OS X" into Terminal. The result may surprise you.

Conclusion

I hope that this little tutorial has helped you demystify the Terminal and realize that it's really not that bad to use – you can achieve a lot more using it and if you want to customize OS X beyond simply changing the wallpaper, then it really is your first port of call.

I hope you have plenty of fun with the commands mentioned above, please feel free to share your own favourites in the comments section below for the benefit of all Mactuts+ readers!

Related Posts
  • Computer Skills
    Tips & Shortcuts
    Quick Tip: Bulk Add Words to Your Mac's Spell Check DictionarySpelling
    The OS X built-in spell check is great, but it is not complete. It often does not include technical terms or brand names. If you routinely use words that your Mac’s dictionary doesn’t contain, and don't want the hassle of adding them one at a time, it might be worth your while bulk adding a list of words. In this tutorial I’ll show you how to do just that.Read More…
  • Computer Skills
    Hardware
    How to Check and Enable TRIM on a Mac SSDTrim preview retina
    You probably know that solid state drives (SSD) differ from Hard Disk Drives (HDD) in how they store information, and you may have heard that something called TRIM can maintain their performance. In this tutorial, I’ll not only show you how you can enable TRIM support for your SSDs, but also understand what the term means and how it fits into the functionality of solid state storage.Read More…
  • Computer Skills
    OS X
    Knowing Your Startup Key Combinations for Intel MacsStartupkeys400 1
    Whilst the idea of the computer mouse (essentially an inverted trackball) has been around since the 1960s, many people were still using keyboards as the sole input method some twenty years on. Even after the mouse became a standard computer accessory in the mid-1980s, many programs relied on keyboard shortcuts to perform particular functions. Even with new input devices, in addition to mice and trackpads, there is still a place for keyboard shortcuts. In this tutorial, I will show you the various keyboard key combinations that perform particular tasks when starting up your Mac.Read More…
  • Computer Skills
    OS X
    Two More Ways to Create an OS X 10.9 Mavericks USB DriveMavericksusb400
    OS X Mavericks 10.9 is the latest iteration of Apple’s desktop computer operating system, released to great fanfare at Apple’s Special Event on 22nd October 2013. Mavericks is distrubuted through Apple’s Mac App Store and is a digital download of 5.29GB. If you have a superfast fibre connection then this may be of little concern. Even a fast ADSL connection and the upgrade can be downloaded reasonably quickly. If you are on a slower internet connection, then this distribution model is not suiting you. In this tutorial, I will show you two ways to install OS X Mavericks onto a bootable USB drive. This is particularly useful if you have two or more Macs to upgrade as it means you only have to download the software once.Read More…
  • Computer Skills
    OS X
    How to Format Your Mac's Hard DriveHdd400
    Unlike personal computers that run Microsoft Windows, it should not be necessary to completely reformat the hard drive, once a year, to reinstall the operating system. You will find that OS X is very stable in comparison, it defragments its hard drive on an ongoing basis and it does not get bogged down with additional software in the way that a Windows machine does. There may be occasions, however, when you want to reformat your Mac's hard drive. In this tutorial, I will show you how to reformat the hard drive in your Mac and reinstall OS X for that factory fresh finish.Read More…
  • Computer Skills
    Terminal
    40 Terminal Tips and Tricks You Never Thought You NeededIcon terminal 2x
    The Terminal is an exceptionally powerful tool, providing a command line interface to the underpinnings of OS X. It’s a topic we’ve covered at length before with our popular series Taming the Terminal. There’s a great deal that Terminal can do, from moving large numbers of files to changing preferences that we didn’t even know exist. To demonstrate just how versatile the Terminal is, I’ve rounded up 40 truly excellent Terminal tips and tricks that can come in very handy. Read More…