Shutdown Mac from the Terminal
I spend most of the time on my Mac working from the terminal. And while there are several other ways to shutdown, restart or put the computer to sleep, I always choose to do so using the command line.
This is also useful for remote machine administration if you’re using SSH or mosh.
I know the topic seems pretty basic, and it is, but I was surprised to find out many colleagues of mine don’t use this method and thought it may be helpful for others.
Usage
To perform all three operations you can use the shutdown
command, which “Close down the system at a given time”.
Shutdown
$ sudo shutdown -h now
Restart
$ sudo shutdown -r now
Sleep
$ sudo shutdown -s now
The command has to be run as root, so unless you’re logged in you’ll need to prefix it with
sudo
In case you want to delay the operation in X minutes, just specify the number after the
-h
flag$ sudo shutdown -h +60
Will shutdown the Mac in 60 minutes.
Pro Tip
I use these aliases in my .zshrc
alias restart="sudo shutdown -r now"
alias shutdown="sudo shutdown -h now"
alias sleep="sudo shutdown -s now"