How to Shut Down a Mac from the Command Line with Terminal
If you want to turn off your Mac using Terminal, I cover a variety of ways to do this. Sometimes turning off your Mac can be a great way to fix some of your issues. Of course, you may say there are many other, perhaps easier, ways to shut down a Mac, like clicking the Restart or Shut Down options in the Apple menu, using keyboard shortcuts or pushing the physical power button. This article is for users who want to know how to shut down their Mac from the command line. Furthermore, this can be used in special circumstances, like in Single-user Mode or Verbose Mode or in remote administration.
Although there are several ways to do this using the command line, we will cover the most used and practical ones. Before going further, I should note that some of the commands below will cause your Mac to turn off immediately without any warning or confirmation. Ensure that you are ready (for example, save any unsaved changes in Pages) to turn off your Mac to ensure you do not experience any data loss.
Use the shutdown command in Terminal on Mac
There are different variations of the shutdown command that you can use to shut down your Mac in Terminal. You can do a shutdown immediately or schedule a shutdown:
Open Terminal (you can open Applications > Utilities to find it), and depending on what you want to do, enter one of the following commands. You will be asked to enter your admin password.
Shutdown immediately
sudo shutdown -h now
This will shut down your Mac as soon as you hit the enter button in Terminal to execute it.
Schedule a shutdown
You can customize this command a little further. You can add time. For example, the following code will shut down your Mac in 10 minutes.
sudo shutdown -h +10
In the screenshot below, I set mine to turn off in 500 minutes. And Terminal told me when the turnoff would occur exactly.
You can customize the shutdown command even more. You can set a time to turn off your Mac in order to schedule a shutdown at a specific time. Change the command like this:
sudo shutdown -h 13:59
The command above will result in a shutdown at 13:59. This will use your Mac’s internal clock to function. This works for 24 hours only. For example, if 13:59 has already passed, it won’t do it the next day at 13:59.
Show a custom message and see warnings/reminders before the shutdown
You can show a custom message to be displayed if you are scheduling a shutdown. Your Mac will show reminders via Terminal when there are 10 min and 5 min left to the shutdown. You can use the minutes or time command and then your message.
sudo shutdown -h +20 "hello macReports.com"
Cancel a scheduled shutdown
So you scheduled your Mac to shut down using the shutdown command in Terminal, but what if you want to cancel it before it happens? You can use the killall command to do this. You can use the following code:
sudo killall shutdown
Related articles