3 terminal commands every Mac users should know


It could refer to the end of a railroad.  It could refer to a place where you catch flights.  But today it refers to that black screen of terror that neophytes run from.  It’s the Windows Command prompt for Mac heads.

I know what you’re thinking.  What can you really do here?  In this guide I’m going to arm you with three terminal tricks that you need to know.

Let’s do this dood.

1. Do it again!!

I’m a big fan of using GNS3 on my Mac.  But there’s one little thing that’s potentially annoying.  In order to create certain virutal interfaces I have to run GNS3 from the terminal.  The only problem is the command is super long and if I forget to start it with sudo I have to backspace the entire thing out and start from the beginning.

For example, let’s say I entered this lengthy command to start GNS3:


Then I realize I should have added the sudo prefix.  Instead of retyping the command or pressing the up arrow and then the left arrow to get to the start of the command, you can just type:

sudo !!

It’s like yelling “Switch user do!!”  The double exclamation points, (or double bangs as I called them) instruct the terminal to repeat the last command.  It’s like a variable for the most recent command.  So to repeat the last command exactly you could press the up arrow once or just type !! and hit enter.

2. Rebuild Spotlight

Spotlight is the super efficient way to search for stuff on your Mac.  Just press Command + space and start typing to search.

Usually it works qmd-uite well but eventually you may discover it feels a little sluggish.  This could mean you just need to rebuild the index.  Which is quite easy indeed.


sudo mdutil -E "/Volumes/DriveName"

Usually the drive name is “Macintosh HD”

This should instantly speed up your Spotlight searches.

Rebuild Spotlight

3. Crash your Mac

Why would you intentionally crash your Mac?  One word: troubleshooting.

Let’s say the fan on your Mac keeps reving up.  Or maybe the topcase feels a little too hot.  If your Mac has intermittent problems when you’re doing a lot of stuff. (Like painting with Photoshop while rendering movies in Cinema 4D while playing Crisis.. talk about a meltdown)  By intentionally maxing out the CPU you can try to reproduce the problem and ascertain the root cause.

First we need to see how many cores you have.

sysctl -n hw.ncpu

Finding the  cores on your Mac

Once you have that, run yes > /dev/null & as many times as you have cores.  Since I have 4 cores I can run it four time to trash my CPU.

yes > /dev/null & yes > /dev/null & yes > /dev/null & yes > /dev/null &

The yes command is actually pretty interesting because, when used by itself, it just keeps printing the letter ‘Y’.  You can read about its obscure history in this 12 page whitepaper on yes by Nick Montfort of MIT.

The Bottom Line

Your Mac is full of secrets.  Now you know how to repeat commands, spruce up Spotlight and crash your mac like an Apple Genius lol.

Do you have any terminal commands that you love to use?  Share the knowledge in the comment below.


Connect with Vonnie on Twitter

Posted in Apple, Mac OS X 10.10 Yosemite, Mac OS X 10.8 Mountain Lion, Mac OS X 10.9 Mavericks Tagged with: ,