10 Mac Terminal Commands That You Probably Didn't Know About

Disclosure: Some of the links on this site are affiliate links. This means that, at zero cost to you, I will earn an affiliate commission if you click through the link and finalize a purchase.

10 Mac Terminal Commands That You Probably Didn’t Know About

The Terminal on a Mac is extremely powerful. Not only does it help you to get things done faster, but it also allows you to finish jobs that you couldn’t have done otherwise.

You don’t need to be a Terminal expert, or even a fan of command-line interpreters, to benefit from this powerful tool.

The list of 10 Mac Terminal commands below should help you improve your Mac experience, whether you’re completely new to the Terminal or just getting started.

1. Disable Sleep Mode : caffeinate

$ caffeinate [-disu] [-t timeout] [-w Process ID] [command arguments...]

There are certain circumstances where it is very useful to stop a Mac from sleeping. Sure there are apps you can download and install to do this. However the quickest and easiest way is to use the caffeinate command!

Enter the caffeinate command into terminal and whilst the terminal application is running, your Mac will not sleep. When you want to exit just press control + C to end the process.

It is also possible to specify several different flags with the command, the most useful being the -t flag.

It is possible to define the number of seconds that the command will stay active. Once the time elapses, the command will automatically exit. For example the following would prevent sleep for one hour.

caffeinate -t 3600

There are also several more complicated flags that can be used with the command. Check out this page for further details.

2. A Better Copy Alternative : ditto

$ ditto [ <options> ] src [ ... src ] dst

Most command line users are familiar with the cp command for copying files and directories, however Mac OS X has the ‘ditto’ function as an alternative.

Ditto is a little more sophisticated than ‘cp,’ and it has several advantages over ‘cp,’ including the ability to maintain not only ownership attributes and rights, but also file resource forks and file and folder metadata, effectively ensuring that the file and/or folders are copied exactly.

If the destination folder does not yet exist, Ditto will create it; if the target folder does exist and contains files, Ditto will merge them.

3. Display A Calendar : cal

$ cal [general options] [-hjy] [[month] year]

Did you know it is possible to display a very authentic calendar in the terminal? If you need to know the date, simply type cal to display the calendar.

There are a series of flags and more options than you would imagine were possible for a simple calendar. For more information, have a read of this.

4. “Get Yo Ass To Bed” : leave

$ leave [[+]hhmm]

Your terminal will give you a persistent reminder that it is time to leave, whether that be the end of your work day or perhaps if you keep staying up until morning doing some kinda Matrix coding.

The leave function waits until the specified time has passed before reminding you to go. You’ll be reminded 5 and 1 minutes before the actual time, as well as at the time and every minute following.

The alarm will sound in hours and minutes from the current time if the time is preceded by a ‘+’ and to get rid of leave, either log out or use kill with its process id as the argument.

5. Your Mac Will Say ANYTHING : say

$ say [-v voice] [-o out] [-f in | message]

Your Mac has a fantastic text to speech synthesis engine built in that can be manipulated by the terminal command say. What you choose to get your Mac to say is your prerogative… 😆

What is really cool is that you can use the -o flag to save the speech as an .aiff audio file for use in your techno remix projects or similar.

There are a whole wealth of other options that you can specify, for further information check out this.

6. Capture Screen To An Image : screencapture

$ screencapture [-icMPmwsWxSCUtoa] [files]

You may already be aware that your Mac has a screen capture program that you can find by using spotlight. You may not be aware that it is also accessible from the terminal.

In the most simple form you can use the command screencapture followed by a file name in .png format to capture the screen the moment the command is executed. The output is saved to the specified file.

There are a whole host of other options that can be used with the command, see here for more information.

7. Transfer Data From The Internet : curl

$ curl [options...] <url>

Another very useful command that I use in many of my tutorials that can be used for grabbing data from remote computers.

If you use curl on a website address, you will be presented with the source code for the relevant page.

$ curl https://siytek.com

However the command is more useful when downloading the contents to a file.

curl https://siytek.com/ -o siytek.html

8. What’s In Your History File? : history

$ history [n]

Your terminal is keeping a track of all of those command that you have been typing. If you type the command without any arguments, you will be shown the last 16 commands entered.

You can also specify a number to show that many previously typed commands. For example, view the last 75 commands typed:

$ history 75

It is also possible to press the up and down arrow keys to cycle through the history. This is very useful if you want to re-execute a recent command!

9. Is Anyone Alive Out There? : ping

$ ping [-AaDdfnoQqRrv] [-c count] [-G sweepmaxsize]

The ping command basically sends out some data packets to a given network address and times the response time.

In its most basic form, this command is great for testing either local network problems or whether a remote server is down.

If you are wondering whether you are having a temporary internet problem, just ping google.com and if you get a response, you know you are good!

ping google.com

10. Grab The Previous Command : !!

$ !!

Typing a double exclamation mark into the terminal will grab the last command entered. This is another seemingly lesser-known shortcut that can be very useful!

A great time to use it is when you execute a command, forgetting to include sudo command to execute the command with superuser privileges. You can quickly correct the error with the following:

sudo !!

Thanks so much for visiting my site! If this article helped you achieve your goal and you want to say thanks, you can now support my work by buying me a coffee. I promise I won't spend it on beer instead... 😏

Leave a Comment

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


Scroll to Top