How To Use Linux Shutdown, PowerOff and Reboot Command
The shutdown, poweroff and reboot commands are the most important power cycle commands in Linux. These commands are specifically used in a situation where you have to bring the server down for maintenance or reboot servers for a kernel upgrade or patches.
Here, we will see how to use the Linux shutdown and poweroff command to shutdown/power-off a system. Also, reboot command to restart the system.
To be able to shutdown or reboot a system, you must be logged in as the root user or a user with sudo privileges.
How to use shutdown command
The shutdown command in Linux safely brings the system down. When we initiate shutdown, all logged-in users are notified that the system is going down and no new logins are allowed, and then all the running process are stopped before the system finally halts.
The shutdown command is a simple command and is available in all Linux flavors like CentOS, Ubuntu, Debian or Fedora.
shutdown [OPTIONS...] [TIME] [MESSAGE...]
Options – Shutdown options like halt (-h), reboot (-r) or power-off (-P default)
Time – Specifies when to perform shutdown (+m, hh:mm or now)
Message – Broadcast message to all logged in users.
When no option used with shutdown command, it will power off the machine. The shutdown process starts after 1 minute (default interval).
Shutdown System Immediately
Use now in shutdown command to bring the system immediately.
Schedule System Shutdown
You can schedule a server shut down by mentioning relative time hh:mm (24 hours format) or +m, where m is the minutes from now to process shutdown.
To shutdown a system after 2 minutes, use:
To shutdown a system at 10:30 PM, use:
Send shutdown Broadcast Message
You can send a custom message to all logged in users as a notification. This option is often useful for scheduled maintenance.
shutdown +15 "The Server will be down for scheduled maintenance"
Use the -r option with shutdown command to reboot the system.
You can also schedule a system reboot like this.
shutdown -r +3
Cancel a scheduled shutdown
For any reason, you want to cancel the scheduled shutdown, use -c option.
How To use poweroff Command
The poweroff command is used to power-off the system.
When used with no options, it will power-off the system immediately.
Use –reboot option with reboot command will reboot the system instead of power-off the system
Force poweroff system
The -f option with poweroff command will forcibly poweroff the system. The system will poweroff instantly just like unplugging the power source of the CPU.
How To use Reboot Command
The reboot command is used to reboot the system.
When used with no options, it will reboot the system immediately.
Power off system
Use -p option with reboot command will power off the system instead of rebooting the system
Force reboot system
The -f option with reboot command will forcibly reboot the system. The system will reset instantly just like pressing the reset button in the CPU.