The 5 Best Terminal Commands for Your Mac

3 minute read
| Deep Dive

You can do quite a bit with your Mac through the user interface (UI). Still, that’s just a snapshot of the true power your computer holds. To really unleash the power of your Mac, you need to visit the Terminal and learn how to use it. Let me give you my five favorite Terminal commands for macOS. Most of these will also work on earlier versions of OS X, by the way.

Terminal commands on macOS are powerful

I added the message to my login screen using one of my favorite Terminal commands

Important Commands For the Terminal

Before we dig deep into the command line, let’s look at some important commands you should know.

  • pwd – Displays the directory you’re currently in
  • cd – Change directory to another one. For example, if I’m in my Home directory (/Users/clefmeister) and type cd Downloads, I’ll be taken to my Downloads folder. On the other hand, typing cd .. will take me to the previous directory in the hierarchy.
  • sudo – This command authenticates you as an administrator for certain commands that need elevated permissions.
  • defaults – The defaults command provides access to the macOS user defaults system, which stores details like whether hidden files are displayed, what happens when you press and hold a key on your keyboard, and quite a bit more.
  • killall – This ends all of the processes named whatever you specify. Use this sparingly, and only when you really mean it.

Those are the primary commands we’ll be using. Let’s move on to my top five Terminal commands for macOS.

1. Add a message to your login screen

Whether you want to remind folks that it’s your computer, not theirs, or just add contact information in case your treasured MacBook Pro is lost, this one is a good tool. Just type the following, replacing my message with yours:

sudo defaults write /Library/Preferences/ LoginwindowText "Stay out! This is Jeff’s Mac, not yours."

2. Stop Your Mac From Going to Sleep

If you’re running an app that’s going to take a while to finish, or recording your screen, you might want to stop your Mac from going to sleep. Sure, you could change your energy saving preferences, but this is much easier. Just type this command and your Mac will stay awake until you cancel it.


When your task is done and you’re ready for your Mac to sleep again, just type Control-C in the Terminal window to end the caffeinate task.

3. Add Spaces to the Dock

terminal command to add spaces to the Dock

You can have nifty spaces in your Dock using this Terminal command

If you want to have cool spaces between different groups of apps on your Dock, that’s easy to do. Just issue these commands and you’ll get a new spacer tile that you can move to the spot you want it to live. This is great for providing more visual organization to your Dock.

defaults write persistent-apps -array-add '{"tile-type"="spacer-tile";}'
killall Dock

Repeat the commands for as many spaces as you want. If you want to get rid of a space tile, just drag it out of the Dock until it goes poof.

4. Turn On Key Repeating for Your Keyboard

When you hold down on a key on your Mac, the default action is for it to display special characters you can type with that key. I talked about this in a previous article about how to type accented characters.

Using a Terminal command to turn on repeating keys

Accented characters are nice, but sometimes you want the keyboard to repeat letters instead

Sometimes, though, you want to go back to the old behavior of having a long keypress result in repeated characters. That’s easy enough to do using this command:

defaults write -g ApplePressAndHoldEnabled -bool FALSE

To reverse it, simply issue this command:

defaults write -g ApplePressAndHoldEnabled -bool TRUE

5. Hide Stuff From the Finder

Let’s say you’ve got a folder you want to keep secret. For example, your collection of Christmas lists and receipts is something you might not want your significant other or children seeing.

Hide folders using a Terminal command

You can hide folders using a Terminal command

You can hide that folder without any trouble, right from the Terminal. Just type this command into the Terminal:

chflags hidden "/Users/clefmeister/Desktop/Folder to Hide"
Folder hidden using a Terminal command

The folder is still in my Desktop directory, but now it’s hidden

To undo what you’ve just done, simply go back to Terminal and type:

chflags nohidden "/Users/clefmeister/Desktop/Folder to Hide"

Bonus Tip – Drag Folder or File Names to the Terminal

That’s right. You don’t have to type out that long folder name you want to hide. Just type in the chflags hidden command, drag your folder into the Terminal window, and watch the magic happen.

What are your favorite Terminal tips and tricks? Let us know in the comments below.

3 Comments Add a comment

  1. ChipMcK

    $ defaults write persistent-apps -array-add ‘{“tile-type”=“spacer-tile”;}’
    2017-04-18 18:41:20.476 defaults[4992:167560] Could not parse: ‘{“tile-type”=“spacer-tile”. Try single-quoting it.

  2. Jeff Butts

    I think I see what’s happened. WordPress automatically changed my quotes to fancy quotes. When you copy and paste them into Terminal, it jumbles them. Let me see if I can fix that, but in the meantime, just replace the quotes (single and double) with regular keyboard strokes.

Add a Comment

Log in to comment (TMO, Twitter, Facebook) or Register for a TMO Account