Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags


What are some useful mac terminal commands?

Programming Bytes

Display the weather, shut down your computer, and more from your terminal

We always want to know things that most people don’t. If you know something that only a few people do, you feel great about yourself. Here are eight fun commands that most people aren’t aware of:

1. Make your Mac talk to you

Yes, your Mac can talk to you. Whatever you say, it will repeat it as shown below:

say “I am Groot.”

say “I am great at impressing people”

The say command will dictate whatever sentence you enter between the double quotes in the default system voice.

You can also change the voice by going to the System Preferences → Accessibility, → Speech → System Voice pop-up menu and choosing a voice.

2. Make your Mac restless

If you’re not performing any interaction with your Mac, it will enter into sleep mode to save energy. However, in some cases, like when taking notes or reading a long article, you may forget to interact with your Mac and then have to enter your password to log in again. To prevent your Mac from falling asleep, you can use the following caffeinate command:


We can also set time periods up so that the command is only temporarily active.

To do this, add the -t flag followed by the number of seconds you want the feature to be enabled for:

caffeinate -t 600

The command above will prevent your Mac from entering the sleep state for 10 minutes (600 seconds). You can stop this by pressing ctrl + c.

3. Download YouTube videos from your terminal

If you want to download YouTube videos, your Mac terminal can do that in a single command. To do this, you need to install youtube-dl in the following way:

brew install youtube-dl

Once youtube-dl is installed, you can download any YouTube video as follows:

youtube-dl "video-url"

There are many options available. You can refer to the documentation for more information.

4. Shut down your Mac

If you want to shut down your Mac using the terminal, all you need to do is type this command:

sudo shutdown -h now

Then, enter your password – this will shut down your computer.

To restart the computer, enter:

sudo shutdown -r now

To shut down your Mac after a certain period of time, you can use this:

sudo shutdown -h +60

The command above will shut down the machine in 60 minutes.

Refer to this page for even more options to shut down your Mac.

5. Make your Mac motivate you with a custom message

Mac allows you to set a custom login message. You can write a motivational quote or, if you want to convey some message to someone using your computer, this is a great choice. I added my address and mobile number on the login screen so, even if I lose my Mac, it would be easy for the person who found it to contact me.

sudo defaluts write /Library/Preferences/ LoginwindowText "Custom Text Here"

This will ask for your administrative password. That’s it. For more detailed info, refer to this page.

6. Make your Mac display the weather forecast

You don’t need to use your browser to get a weather forecast. You can do it from your terminal with a single-line command:


It will bring you the weather forecast for the upcoming #key# three days: with morning, noon, evening, and night sections.

This will be really helpful if you’re a frequent traveler.

To get the weather report for a particular city, you can use:


7. Get the history

You can get your terminal command history using:


If you’re searching for a specific word from the command history, you can use:

history | grep cd

The command above will list all the commands in the history that include cd.

If you want to clear the command history, you can use:

history -c

8. Change save location of the screenshot

If you want to save your screenshot in a custom location, you can use this command:

defaults write location ~/your/location/here

After this, enter this command:

killall SystemUIServer



View all Courses

Keep Exploring