shutdown command in Linux with Examples
The shutdown command in Linux is used to shutdown the system in a safe way. You can shutdown the machine immediately, or schedule a shutdown using 24 hour format.It brings the system down in a secure way. When the shutdown is initiated, all logged-in users and processes are notified that the system is going down, and no further logins are allowed.
Only root user can execute shutdown command.
Syntax of shutdown Command
shutdown [OPTIONS] [TIME] [MESSAGE]
-r : Requests that the system be rebooted after it has been brought down.
-h : Requests that the system be either halted or powered off after it has been brought down, with the choice as to which left up to the system.
-H : Requests that the system be halted after it has been brought down.
-P : Requests that the system be powered off after it has been brought down.
-c : Cancels a running shutdown. TIME is not specified with this option, the first argument is MESSAGE.
-k : Only send out the warning messages and disable logins, do not actually bring the system down.
How to use shutdown
In it’s simplest form when used without any argument, shutdown will power off the machine.
How to shutdown the system at a specified time
The time argument can have two different formats. It can be an absolute time in the format hh:mm and relative time in the format +m where m is the number of minutes from now.
The following example will schedule a system shutdown at 05 A.M:
sudo shutdown 05:00
The following example will schedule a system shutdown in 20 minutes from now:
sudo shutdown +20
How to shutdown the system immediately
To shutdown your system immediately you can use +0 or its alias now:
sudo shutdown now
How to broadcast a custom message
The following command will shut down the system in 10 minutes from now and notify the users with message “System upgrade”:
sudo shutdown +10 "System upgrade"
It is important to mention that when specifying a custom wall message you must specify a time argument too.
How to halt your system
This can be achieved using the -H option.
Halting means stopping all CPUs and powering off also makes sure the main power is disconnected.
How to make shutdown power-off machine
Although this is by default, you can still use the -P option to explicitly specify that you want shutdown to power off the system.
How to reboot using shutdown
For reboot, the option is -r.
You can also specify a time argument and a custom message:
shutdown -r +5 "Updating Your System"
The command above will reboot the system after 5 minutes and broadcast Updating Your System”
How to cancel a scheduled shutdown
If you have scheduled a shutdown and you want to cancel it you can use the -c argument:
sudo shutdown -c
When canceling a scheduled shutdown, you cannot specify a time argument, but you can still broadcast a message that will be sent to all users.
sudo shutdown -c "Canceling the reboot"