Server – Shutting Down
So far, so good, but how do you power down or reboot from the command line?
There are, as with many things Linux, several options including halt, shutdown, and with systemctl commands.
My preference is the shutdown command.
Shutdown and Power Off Now
To use the shutdown command, you have to specify what you want the server to do when the operating system is halted, and a time when you want the action to occur.
sudo shutdown -h now
will halt the operating system gracefully, then power the system off, and run the command immediately.
The -h option is needed to power the system off after the operating system stops.
now means the command should be run immediately. You can specify a wait time here if you want instead.
Rebooting is similar.
sudo shutdown -r now
You just specify the -r option for reboot.
When To Shut Down
As with Windows, you should not simply power off a running system by hitting the power button, whether you’re running a physical system or running on a virtual platform like VirtualBox or VMware.
Telling the operating system you want it to shutdown gives it a chance to do house keeping and gracefully shutdown processes, and to shutdown only when that is complete.
If you just power off, you may find it in an unstable state when you reboot.
Always do a shutdown whenever possible before powering off.
The rare exception being when the system will not respond to any input, and you have to power cycle it to recover.