Reboot Mac OS X from the Command Line
Rebooting a Mac from the command line is fairly simple, though it should be pointed out that most Mac OS X users are best served just using the standard Apple menu method to issue a system restart.
Nonetheless, for advanced Mac users, using the terminal reboot command can be an invaluable trick for troubleshooting purposes, remote systems administration, remote management through SSH, after installing software updates on a Mac through the command prompt, and a great number of other reasons.
How to Restart a Mac from the Mac OS X Command Line
To start a reboot immediately from the Mac OS X Terminal, type the following command string at a prompt (either locally or remotely):
sudo shutdown -r now
Next you’ll need to enter the administrator password when requested, that’s because the command is prefixed with sudo, which gives the shutdown command superuser privileges that are necessary to issue the reboot command.
The Mac will be immediately restarted regardless of what’s going on, so be sure not to use this if important documents are open and you have something like auto-save turned off.
Another option is to use the following different command to reboot a Mac from the command line:
osascript -e 'tell app "System Events" to restart'
How to Reboot from the Command Line with a Message
You can add a message to the reboot notice for those logged in through SSH by adding a quote at the end like so:
sudo shutdown -r now "Rebooting Now for OSXDaily.com"
This looks like the following to anyone logged into the Mac:
Shutdown NOW!
*** FINAL System shutdown message from user@hostname ***
System going down IMMEDIATELYRebooting Now for OSXDaily.com
System shutdown time has arrived
The reporting will reference shutdown whether you are rebooting, shutting down, or sleeping, which is why it can be useful to append a message to the command, which is reported back as the second to last line. Also, the “user@hostname” will be that of whom initiated the reboot.
Using this shutdown command, it would also be easy to modify a past trick to remotely sleeping a Mac to be able to remotely reboot or shutdown a Mac instead.
The shutdown command has been around since the earliest days of Mac OS X and still exists in Lion, Mountain Lion, Mavericks, and Yosemite, Sierra, Mojave, onward. As you may have guessed, the shutdown command can be used for other tasks like actually shutting the Mac down, putting the Mac to sleep instantly like pmset, and more.
hi
can i change the input source with command line / terminal?
Is there a way to reboot in to specific run states like Single User and Recovery from the command line?
Use “sudo reboot” unless you want a forgotten “-r” option to cause some unintended travel.
Don’t forget shutdown -h now for halt
Halt from my understanding is much rougher on the system.
Think graceful shutdown versus just sending kill signals. Do not recommend “halt” unless you are truly frozen.
“sudo reboot” does the same
Why not just use:
sudo halt
For sysadmins why not use a single command instead of logging in then issuing the command?
ssh user@hostname sudo shutdown -r now “rebooting your Mac”
Then you only have to enter the admin password once.
Great trick, thanks!
That’s not a trick, that’s rather standard command for UNIX/BSD’s ;-)
Or even simply, just substitute “reboot” for “shutdown -r now”; it does exactly the same thing and requires less typing.