5 Useful Terminal Tricks for Mac Users

Buried underneath your Mac's pretty interface is a decades-old backbone called UNIX, and you can use its old-school Terminal for running simple commands that aren't accessible from the apps or menus. These aren't just useful for developers and hackers—even if you've never delved into the Terminal before, there are a few tweaks that'll make your Mac better and boost your command line confidence. The Terminal app is stored under Applications > Utilities, but you can launch it quickly at any time by pressing Command+Space to open Spotlight, searching for "Terminal," and pressing Enter.

Set a Shutdown Timer

Here's an easy one. I sometimes want to keep my computer on for an hour or two while a job finishes (like a big download) and have it shut down when it's done. To set a timer for shutdown, open a Terminal window and run:

sudo shutdown -h \+60

To break down that command, here's what it does:

  • sudo tells the Terminal to run the following command as a super user, or administrator. You'll need to enter your password, though it won't show asterisks when you type. Don't worry, it's receiving your keystrokes.
  • shutdown is the main command we're sending to the system.
  • The -h flag tells it to halt, or shut down. You can replace this with -r if you want to restart, or -s if you want to put the computer to sleep instead.
  • Finally, the +60 is our timer in minutes. The above command tells the system to shut down after 60 minutes, or one hour—but you can replace this number with any amount of time you want. You can also use a specific date and time in the format yymmddhhmm if you want.

sudo killall shutdown

… which kills the shutdown process running in the background.

Prevent Your Mac From Falling Asleep

On the other side of the coin, you may want to prevent your Mac from going to sleep using its automatic energy-saving features. In this case, you can just use the "caffeinate" command to set an anti-sleep timer:

caffeinate -u -t 3600

The -u flag tells the system to act as if the user is active (so the display doesn't go to sleep either), while -t sets a timer for, in this case, 3,600 seconds (or one hour). At that point, your usual energy savings rules will come back into effect.

Show Hidden Files and FoldersIn general, most people shouldn't need to view or edit any hidden files. They're hidden for a reason: The system needs them, you don't. But if you find you need to access one for some reason—or you want to hide some secret files of your own—you can run the following command to show hidden files in the Finder: