5 Mac Terminal tips you’ll want to use

Apple’s Terminal application is supremely powerful on your Mac. Here are five Mac Terminal tips most Mac users may want to use.

Apple, Mac, macOS, OS X, Macintosh, Terminal, tips
IDG

Apple’s Terminal application is supremely powerful on your Mac, and while you should be wary when using it, you can benefit from some super-useful Mac tricks if you do.

What is Terminal?

The Terminal application can be understood as a text-based user interface with which to control your Mac using command line tools. These are very powerful, and they enable you to change lots of the ways your Mac usually behaves.

Be warned

Terminal is unforgiving. You don’t need to fear it, but you should be very, very careful to use precisely the right code when entering instructions for your Mac — particularly if using any command including the word "sudo".

What will I learn?

I’m going to share five neat Terminal tips:

  • How to change default screenshot image format
  • How to create a Recent Applications folder
  • How to flush Mac memory
  • How to fix your Mac (sometimes)
  • How to stay up forever

How to change default screenshot image format

Your Mac saves screengrabs as PNG files by default. That’s great, but you’ll probably want to create lower-res files if you want to share them online. To save screenshots in another format, open Terminal and type:

defaults write com.apple.screencapture type JPG

As you can see, in this case I’ve chosen to save images as JPG, but you can also use PDF, TIFF, or any other image format your Mac natively supports. To return your Mac to default behavior, just type the above code but replace JPG with PNG.

How to create a Recent Applications folder

You can use Terminal to create a “Recent Applications” stack in the right-hand section of your Dock. Open Terminal and type:

defaults write com.apple.dock persistent-others -array-add '{ "tile-data" = { "list-type" = 1; }; "tile-type" = "recents-tile"; }';killall Dock

Now Control-click your new Dock item, and you’ll find options to change what it does in order that it will show you Recent Applications, Documents, Servers, Favorite Volumes or Favorite Items. Here are some more Terminal tips for your Dock.

How to flush Mac memory

I recently noted this on my own little blog, but I thought it useful enough to also include here: When/if a Mac becomes unresponsive, the usual response is to restart the computer because doing so frees up system memory and usually makes things run better again. The disadvantage is that before you do so, you need to save current projects and switch off some apps. However, this Terminal tip (which you must be careful with when using because it uses the "sudo" command) will have the same effect without a restart. To use it, open Terminal and type:

 sudo purge 

(or just purge on Macs running a pre-Sierra OS).

You’ll be asked for your password, and you should see Mac performance improve.

How to fix your Mac (sometimes)

File System Consistency Check (‘fsck’) will check and repair file systems on your Mac and will sometimes be enough to get your computer working again.

Boot up in Single User mode by starting it up while pressing Command-S. You should hear the start-up chime and see white text on a black background appear.

When the Mac starts up you should see a command line prompt on screen — it basically looks like Terminal. Now type this:

fsck fy

  • A bunch of code will appear on-screen until the check is complete.
  • You will then see either “File system was modified”, or “The volume (name) appears to be OK”.
  • If you see the first statement, you must run the fsck –fy operation again. You may need to run it several times until the reassuring message that tells you “The volume (name) appears to be OK” appears.
  • It is only then that the Mac will have been fixed. If the message never appears, then your Mac likely has a problem software cannot fix..

When you finish (or give up), type reboot to leave Single User Mode and launch the Mac as normal. More here.

How to stay up forever

There are times — particularly when making a screen recording or using an app that has a big task to complete — when you want to make sure your Mac doesn’t go to sleep. That’s what the caffeinate command does for you.

Open Terminal and type:

caffeinate

Your Mac will now stay awake until the task completes. To switch the command off and get your Mac working normally again, just type Control-C in the Terminal window.

Another way to make sure you don’t leave this command active for longer than you want is to modify it slightly by putting it on a timer. To do that, type:

caffeinate -t 3600

This command will caffeinate your Mac for an hour (3,600 seconds), after which it will perform normally again.

There’s lots more to learn about this tool.

Google+? If you use social media and happen to be a Google+ user, why not join AppleHolic's Kool Aid Corner community and get involved with the conversation as we pursue the spirit of the New Model Apple?

Got a story? Please drop me a line via Twitter and let me know. I'd like it if you chose to follow me there so I can let you know about new articles I publish and reports I find.

Enterprise mobility 2018: UEM is the next step
  
Shop Tech Products at Amazon