Cool Mac terminal hacks and shortcuts

James Scott
3 min readJul 17, 2019

--

Here is a collection of command line hacks and shortcuts for your Macbook that may save you time and make your life easier… some of the others are just a bit of fun!

Make Touch ID your sudo password

If you own or use a Macbook Pro with a Touch Bar you can make your fingerprint your sudo password. To do this:

  1. Open a terminal and edit /etc/pam.d/sudo
  2. Add the following line at the top of this file:auth sufficient pam_tid.so

3. Save the changes.

The next time you need to enter the sudo password you can just use your fingerprint!

Enable your mouse cursor in VIM editor

If you want to be able to use your mouse in any file you open in VIM:

  1. Create and edit a new file:vim ~/.vimrc
  2. Add this line to the file: set mouse = a
  3. Save the file.

You can now use your mouse cursor to navigate and edit different parts of a file while using VIM editor:

Converting Unix Epoch time

Previously whenever I wanted to convert Unix Epoch time to human-readable time, I always used https://www.epochconverter.com. It’s actually quite embarrassing how often I used this site until I discovered you can simply run date -r followed by the Epoch timestamp from the command line.

Get your Macbook to speak

Type “say” following by text and your Macbook reads it out.

For fans of 2001: A Space Odyssey

If you want to see a list of all of the available voice options in the Mac OS version you have installed, run this command: say -v '?'

Stop your Macbook from falling asleep

You can stop your Macbook from falling asleep using caffeinate followed by the time in seconds you want your laptop to stay awake for:

caffeinate -t 6000

View all previous commands

Use history to view all previous commands you have run from the terminal.

Or if you don’t want anyone to see what commands you’ve run previously, you can delete your command history using:

history -c 

Get the weather forecast

You can send a cURL request to retrieve the current weather forecast. Type the following command: curl http://wttr.in/ <your_city_name> .

For example, curl http://wttr.in/ london returns the following:

Play Games

If you simply want to play some old school games from your terminal:

  1. Open your terminal and runemacs
  2. Press Enter followed by Esc.
  3. Type ‘x’ and enter the name of the game you want to play such as ‘tetris’:

4. Other valid options include: ‘snake’, ‘pong’, ‘doctor’, ‘landmark’, ‘gomoku’, ‘dunner’ or ‘solitaire’ (the marble game, not the card game!)

Have fun!

--

--

James Scott

Technical writer. I write about technical writing, documentation tools & trends, API documentation, AI and the etymology of words used in technology.