How to Shutdown a Mac from Terminal

Aug 13, 2017 - 20 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.

.

Related articles:

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

20 Comments

» Comments RSS Feed

  1. Giorgi says:

    How to prevent reopening programs after turning mac on?

  2. DAVID says:

    Thank you

  3. chmod07 says:

    It’s just like windows they have shutdown commsnd when you updating the windows patches.i got no time to wait to shutdown i just type the command on search button or you cmd .
    this is just basic commsnd for unix wait until you need to search some hidden files more command. 20 years ago mac os purely unix command when it comes restore the mac but now apple make it simple .

  4. Adam says:

    Great tip I learned how to shut down the Mac from the command line with this. I use to use shutdown -h now in Linux but had long forgotten the commands.

  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.

  6. mike says:

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

  7. Dan Uff says:

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

  8. 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.

    • Tealeaf says:

      I use `osascript -e ‘tell app “System Events” to shut down’` and worked just fine.

      Got this:

      “*** FINAL System shutdown message from user@host ***
      System going down IMMEDIATELY”

      Then I had to go across town to locally switch it back on. Any osascript magic to switch the machine back on, remotely?

      • D Gryphon says:

        If you haven’t found it already, you’re going to groan a bit.

        osascript -e ‘tell app “System Events” to restart’

  9. 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.

        • Uhuh says:

          Well… your nick certainly suits you… because there is NO WAY you’ve been a sysadmin for over two decades and haven’t happened upon a situation where you’ve needed to shutdown a Mac via the CLI.

          For one, as a true sysadmin, I SSH into our Macs (typically moreso the servers – Minis, etc – but also the workstations on occasion), and shutting down/restarting via command line is the quickest option.

          For two, it’s what a true sysadmin would be used to, having administered mixed platform environments including *NIX, Windows and Mac systems.

          For three, using the shutdown command via the terminal CLI is no more “dangerous” than choosing the wrong menu item or clicking the wrong button on a GUI… and it’s 10x’s more efficient because I don’t have to stop and reach for a mouse.

          So, really, you’re definitely not inspiring confidence in your sysadmin skills right now… especially if you don’t think you can accurately type an 8 letter command in a terminal.

    • Sebastián Camilo Barón Barbosa says:

      obviously if you are using this method is because the regular one did not work! duh

    • Artur says:

      you’re wrong…
      I just used the command as the top bar did not want to pop up. Shutting down with the buton is not too healthy for the HDD.

      Cheers !

Leave a Reply

 

Shop on Amazon.com and help support OSXDaily!

Subscribe to OSXDaily

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

Tips & Tricks

News

iPhone / iPad

Mac

Troubleshooting

Shop on Amazon to help support this site