Terminal Tricks for Mac

UNDERNEATH THE SURFACE YOUR Mac’s pretty GUI is based on UNIX, a decades-old operating system, and you can use its old-school Terminal to execute basic commands that aren’t available via the software or menus. These aren’t just for developers and hackers; even if you’ve never used the Terminal tricks before, there are a few tweaks that will improve your Mac and increase your command-line trust.

Since the Terminal app is located in Applications > Utilities, you can access it at any time by pressing Command+Space to open Spotlight, searching for “Terminal,” and pressing Enter.

5 Useful Terminal Tricks for Mac Users:

1: Set a Shutdown Timer:

Here’s a quick one. I occasionally want to leave my machine on for an hour or two as a job completes (such as a huge download) and then turn it off when it’s done. To set a shutdown timer, open a Terminal window and type:

sudo shutdown -h +60

Here’s a breakdown of what the order does:

  • The command sudo tells the Terminal to run as a superuser or administrator. You’ll need to enter your password, but asterisks will not appear as you type. Don’t worry, your keystrokes are being sent.
  • The main command we’re sending to the system is shutdown.
  • The -h flag indicates that it should halt or shut down. If you want to restart the machine, replace this with -r, or if you want to put it to sleep, use -s.
  • Finally, the +60 reflects our minute timer. The command above tells the machine to shut down after 60 minutes, or one hour, but you can change the number to whatever you want. If you want, you can use a particular date and time in the format yymmddhhmm.

Simply run: to cancel your timer before it expires.

sudo killall shutdown

Which terminates the shutdown process that is currently running in the background?

2: Prevent Your Mac From Falling Asleep:

On the other hand, you may want to use your Mac’s automatic energy-saving features to prevent it from going to sleep. You may simply use the “caffeinate” command to set an anti-sleep timer in this case:

caffeinate -u -t 3600

The -u flag tells the machine to behave as if the user is present (so the monitor doesn’t go to sleep), while the -t flag sets a timer for 3,600 seconds in this situation (or one hour). At that point, the normal energy-saving recommendations will restart.

3: Show Hidden Files and Folders:

Most people shouldn’t need to access or edit any secret files in general. They’re secret because the machine needs them, but you don’t. If you need to access one for some reason—or if you want to hide some secret files of your own—run the following command in the Finder to see hidden files:

defaults write com.apple.finder AppleShowAllFiles -bool TRUE

Then, to ensure that the changes are applied, restart the Finder by typing:

killall Finder

You may also use some ampersands to combine those two orders.

defaults write com.apple.finder AppleShowAllFiles -bool TRUE && killall Finder

(I’ll do the same for the rest of the commands in this list that include restarting a service for the sake of simplicity.)

You may use the following command to hide your own folder or file:

chflags hidden ~/Dekstop/MySecrets && killall Finder

… substituting the path to your own private folder or file for /Dekstop/MySecrets. (The denotes your home folder, which can also be found at /home/[yourusername].) To make secret files and directories available again, simply use FALSE instead of TRUE in the original command.

4: Customize the Dock:

The Dock is a key part of the macOS user interface: It’s where you keep your most-used shortcuts, switch between windows, and cover minimised apps you don’t need right now. Although macOS’ Settings > Dock menu contains some useful tweaks, you can customise it even more with a few terminal commands.

For example, if you want to to add a blank spacer to help organize your apps into groups? Run:

defaults write com.apple.Dock persistent-apps -array-add ‘{“tile-type”=”spacer-tile”;}’ && killall Dock

Alternatively, if you want to keep the dock as simple as possible, you can use the following command to cover all apps that aren’t currently running:

defaults write com.apple.Dock static-only -bool TRUE && killall Dock

If you regularly use Command+H to “hide” apps, you can also dim their icons in the dock to indicate that they’re hidden:

defaults write com.apple.Dock showhidden -bool TRUE && killall Dock

Finally, if you want to automatically display and remove the Dock, you’ve probably found that there’s a one-second pause in the animation—that is, when you hover over the bottom of your screen, the Dock slides in after about a second. Run the following commands to get rid of the lag:

defaults write com.apple.Dock autohide-delay -float 0 && killall Dock

You can also increase the delay by changing the 0 to a higher amount. Run the following command to restore the default auto-hide settings:

defaults delete com.apple.Dock autohide-delay && killall Dock

5: Tweak the Way Your Mac Takes Screenshots:

On a Mac, taking a screenshot is simple: To capture a window or a portion of the screen, simply press Command+Shift+4. Unfortunately, from the on-screen menus, you don’t have much influence about how these screenshots are saved. The Terminal, on the other hand, allows you to configure items.

For example, if you want to adjust where screenshots are saved, run:

defaults write com.apple.screencapture location ~/Pictures && killall SystemUIServer

/Pictures should be replaced with whatever folder you choose to use. Replace that direction with /Desktop instead if you want to revert to the default behavior.

After that, use the following command to delete the drop shadows around screenshots:

faults write com.apple.screencapture disable-shadow -bool TRUE && killall SystemUIServer

You can resurrect them by replacing TRUE with FALSE in the command.

You may also adjust the file form of those screenshots, which is by default PNG, to something else with:

defaults write com.apple.screencapture type JPG && killall SystemUIServer

If you prefer, you can replace JPG with a few other file forms, such as PDF.

Finally, you have the option of changing the default name of the screenshot files. Use the following command:

defaults write com.apple.screencapture name “mycapture” && killall SystemUIServer

Replace mycapture with whatever you’d like for the filename. You should be able to get your Mac to take screenshots exactly how you want them with only a few commands and no additional software.


This article highlights the important points that every Mac user should know about and can use their device more effectively by using all the above-mentioned commands.

Leave a Reply

Your email address will not be published. Required fields are marked *