How to Shutdown a Mac from Terminal

Aug 13, 2017 - 11 Comments

Terminal in macOS

Advanced Mac users may wish to shut down a computer from the command line. This can be helpful for remote administration with ssh, in situations where a Mac is booted into Single User Mode, or many other circumstances of troubleshooting and systems administration.

There are several ways to shut down a Mac from the command line, we’ll cover two of the most simple methods using easy syntax.

The Mac Terminal offers many commands for handling various tasks and system functions, and so naturally the command line also offers a method to shutdown a Mac computer from the Terminal as well.

An important word of warning: shutting down a Mac through the command line happens instantaneously. There is no confirmation, no warning dialog, no stopping to save documents, no asking to close apps or save anything. Instead, the Mac will instantly terminate any and all activity going on and immediately shut down the computer. This could lead to data loss, so be sure you are ready to turn off a Mac if you issue these commands.

Shutting Down a Mac from Command Line with ‘shutdown’

Apt for the name, the ‘shutdown’ command can shutdown a Mac as well as reboot a Mac via Terminal. To turn off a Mac with the shutdown command, you will use the -h flag and give the time for ‘now’ making the syntax like so:

sudo shutdown -h now

As soon as you hit return and authenticate the command, the Mac halts and kills all applications and processes and shuts the computer down. There is no warning and no dialog, it happens instantly.

Unless you’re actively logged in as the root user (via single user or otherwise), you will need to prefix the shutdown command with ‘sudo’ to give the command superuser privileges, thus requiring an administrative password.

If you feel like trying this yourself (and you have all data saved and nothing important open) do the following:

  1. Open the Terminal in Mac OS (found in /Applications/Utilities/ folder)
  2. Enter the following command syntax exactly:
  3. sudo shutdown -h now

  4. Hit the return key and authenticate with an administrative password to immediately shut down the Mac

Shutdown a Mac from Command Line

The Mac will immediately shut down. No data is saved and no dialogs are confirmed, the shut down happens instantly.

You can also use the -h flag to set a time or date for shutting down the computer, for example in 30 minutes, but if you want to shut down the Mac instantly you would use the ‘now’ parameter with the -h flag rather than a number.

Shutting down a Mac in XX Minutes from the Command Line

If you do feel like putting a delay on the shutdown, you can use the following command syntax instead:

sudo shutdown -h +30

Replace “30” with any other number of minutes to shut down the Mac in that amount of time. For example if you put “2” instead of 30 then you would shut down the Mac in 2 minutes.

Shutting Down a Mac via Terminal with ‘halt’

The ‘halt’ command can also instantly shut down a Mac via the command line. The process and syntax for ‘halt’ to turn off a Mac is as follows:

  1. Open the Terminal .app in Mac OS
  2. Enter the halt command syntax exactly as described:
  3. sudo halt

  4. Hit the return key, authenticate with sudo to instantly shut down the Mac

Whether you use ‘halt’ or ‘shutdown’ does not matter really, it’s mostly preference and what you can remember when necessary.

By the way, the shutdown command can also be also be used to restart a Mac from the command line by using the -r flag instead of the -h flag.

Keep in mind that for most users the command line approach is not going to be better or faster than accessing the  Apple menu Shut Down option or using the power button keyboard shortcuts, this is really aimed at advanced users who are already at the command line anyway.

Enjoy this tip? Subscribe to the OSXDaily newsletter to get more of our great Apple tips, tricks, and important news delivered to your inbox! Enter your email address below:

Related articles:

Posted by: Paul Horowitz in Command Line, Mac OS X, Tips & Tricks

11 Comments

» Comments RSS Feed

  1. no way says:

    This is idiotic, why risk a terminal mistake when you can simply go to Apple upper left of screen and click shut down. If you are connected remotely this works exactly the same.

    I guess OSXDaily is just running out of good advice, and posting bad in it’s place.

    • Fool Factory says:

      “no way” you personally should definitely stick to novice level material like your little Apple menu trick because this is obviously over your head, which is fine, you’re a novice level user. Everyone starts somewhere.

      If you don’t know why people use the Terminal or would want to shutdown from the command line you should probably not comment about it, it makes you sound even less intelligent than your comments already are.

    • Darren O'Brien says:

      Actually shutting down a Mac by command is very useful to every sysadmin.

      If you don’t understand a subject but you attack that subject because you don’t understand it yourself, that makes you the idiot. You’re being willfully ignorant. In fact, you would be less of an idiot yourself if you bothered to learn a thing or two.

      • no way says:

        I understand the subject perfectly well, have been a system admin and senior level repair for Apple for over two decades.

        Instead of whining and trash talk prove me wrong.

        Bottom line doing ANYTHING via terminal remotely is a risk that no experienced tech would ever do when they can do it via the user commands.

  2. Sam says:

    This advice is just plain wrong and will lead to corruption and lost data if you follow it. DO NOT follow this advice.

    Both commands send programs a UNIX style shutdown command. GUI programs do not expect this and will terminate WITHOUT giving you the chance to save your data or clean themselves up. (Specifically, Cocoa apps do not see applicationShouldTerminate: or the kAEQuitApplication Apple Event)

    The correct way to safely shutdown from the command line is “osascript -e ‘tell app “System Events” to shut down'”

    • Erik says:

      Sam, you’re wrong. This shuts down a Mac from the command line. Did you even bother read the article? Obviously not. There are multiple warnings that it does not request a data save. There’s a giant paragraph at the beginning of the article.

      How did you manage to get this far without reading the article? Maybe this site needs a system to verify that people read the article before they can comment.

      “An important word of warning: shutting down a Mac through the command line happens instantaneously. There is no confirmation, no warning dialog, no stopping to save documents, no asking to close apps or save anything. Instead, the Mac will instantly terminate any and all activity going on and immediately shut down the computer. This could lead to data loss, so be sure you are ready to turn off a Mac if you issue these commands.”

      Also to say it is “wrong” is itself wrong, because “wrong” is by definition incorrect. The article is correct, even if you don’t agree with it. That makes it TRUE.

      Why don’t you do your own research, type “man shutdown” into the command prompt and you will see that it is REAL and TRUE. Facts matter.

      • Sam says:

        You are wrong about reading the man page. The man page was never updated for macOS. Read the bottom of the man page. It says “BSD December 11, 1998”. That means Apple never updated the man page for OS X, otherwise it would say DARWIN or macOS (try man diskutil or pmset). Therefore do NOT trust the information.

        There is NO reason to use BSD shutdown unless the system is stuck. There is a perfectly good command line method which I provided, which is safe and does not result in data loss.

        In general, Apple does recommend applications or users work with the BSD interfaces and utilities in macOS. This is a prime example why.

        • Gombo says:

          Sam if you’re booted into recovery or single user as root and need to shutdown a Mac, how do you propose doing that?

          The answer is the shutdown command.

  3. Dan Uff says:

    Well, for those of us who use the Terminal this trick is appreciated. Thank you.

  4. mike says:

    The “reboot” command was not listed, but is sometimes very handy.

  5. Endymion says:

    Today we have only seven ladder manufacturers in the US, down from >100. Why; not globalization, nor a decline in the market but rather the lawsuits from people who fell off ladders and sued all the small operations. The desire for an idiot-proof world is here again on this thread. CLI and its risk/benefits are not for the foolhardy. People like this are the reason why construction trucks make that beeping noise when backing-up.

Leave a Reply

 

Shop for Apple & Mac Deals on Amazon.com

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates