The Linux Shutdown Command is used to stop the operating system safely. Users logged in receive a message that the system will be shut down. The command allows the system to shut down immediately or according to a set period of time. In this tutorial you will learn the basic ways to use the shutdown command as well as the best practices in using it. In some of the newer distributions, the uptime command is associated with the system command systemctl. In addition we are going to explore how to reboot how to schedule reboots, how to warn logged in users and more.
Basic syntax for all commands
Basic practices to use for shutdown , restart and user notice
Alternative commands
60 second video tutorial for easier adaptation
Before we move on, let's look at the basic syntax of the command.
shutdown [options] [time] [message]
This is the output of the man page:
shutdown may be used to halt, power-off or reboot the machine.
The first argument may be a time string (which is usually "now").
Optionally, this may be followed by a wall message to be sent to all
logged-in users before going down.
The time string may either be in the format "hh:mm" for hour/minutes
specifying the time to execute the shutdown at, specified in 24h clock
format. Alternatively it may be in the syntax "+m" referring to the
specified number of minutes m from now. "now" is an alias for "+0",
i.e. for triggering an immediate shutdown. If no time argument is
specified, "+1" is implied.
Note that to specify a wall message you must specify a time argument,
too.
If the time argument is used, 5 minutes before the system goes down the
/run/nologin file is created to ensure that further logins shall not be
allowed.
shutdown --help output
shutdown --help
shutdown [OPTIONS...] [TIME] [WALL...]
Shut down the system.
Options:
--help Show this help
-H --halt Halt the machine
-P --poweroff Power-off the machine
-r --reboot Reboot the machine
-h Equivalent to --poweroff, overridden by --halt
-k Don't halt/power-off/reboot, just send warnings
--no-wall Don't send wall message before halt/power-off/reboot
-c Cancel a pending shutdown
The first example will immediately shutdown the operating system without any warnings to the other users:
shutdown -h now
In this case if you are using a ssh connection it will be terminated immediately. In the next example shutdown is going to be postponed for two minutes:
# shutdown -h (time in minutes)
$ shutdown -h 2
Shutdown scheduled for Mon 2021-03-22 18:52:31 EET, use 'shutdown -c' to cancel.
Now as we see in the output we can use another option to cancel the request:
# cancel shutdown request
$ shutdown -c
After running shutdown -c we are not going to see another output but the above command shutdown -h 2 will be terminated. An alternative method to shutdown -h is shutdown + like the next example:
# Shutdown server after 10 minutes
$ shutdown +10
Shutdown scheduled for Mon 2021-03-22 19:04:53 EET, use 'shutdown -c' to cancel.
Now lets create a more practical example. We want to shutdown the server after 30 minutes and all users to be informed about our action.
# Shutdown the server after 30 minutes and inform logged users
$ shutdown +30 "The server will be shutdown for maintenance after 30 minutes please log out all of your sessions!"
Shutdown scheduled for Mon 2021-03-22 19:28:27 EET, use 'shutdown -c' to cancel.
We can do even one better than that lets say we want to inform all users that the server will be shutdown at a specific time:
# Shutdown the server at a specific time and message
$ shutdown -h 21:00 "The server will be shutdown for maintenance at 21:00 please log out all of your sessions!"
Shutdown scheduled for Mon 2021-03-22 21:00:00 EET, use 'shutdown -c' to cancel.
Please note that in all examples except shutdown now, you can use shutdown -c to cancel the shutdown process.
If you use scheduled server shutdowns. They will most likely be restarts. Our latest example would be a command that will perform a scheduled restart of the server at a specific time and notify users.
# Scheduled server restart
$ shutdown -h 21:00 "The server will be restarted for maintenance at 21:00 on 23-03-2021 please log out all of your sessions!" -r
Reboot scheduled for Tue 2021-03-23 21:00:00 EET, use 'shutdown -c' to cancel.
A fast reboot method without any warnings or a schedule can be performed with the command reboot:
# A immediate reboot method
$ reboot
A reboot can be forced like a physical reset button an a computer:
# A immediate forced reboot
$ reboot -f
Another great command for shutting down a linux distribution is the halt command. Here is the basic syntax for halt:
halt [OPTION]
And the help for halt:
$ halt --help
halt [OPTIONS...]
Halt the system.
Options:
--help Show this help
--halt Halt the machine
-p --poweroff Switch off the machine
--reboot Reboot the machine
-f --force Force immediate halt/power-off/reboot
-w --wtmp-only Don't halt/power-off/reboot, just write wtmp record
-d --no-wtmp Don't write wtmp record
--no-wall Don't send wall message before halt/power-off/reboot
See the halt(8) man page for details.
And for final alternative command you can use poweroff, here is the syntax:
poweroff [OPTION]
And the help for poweroff:
$ poweroff --help
poweroff [OPTIONS...]
Power off the system.
Options:
--help Show this help
--halt Halt the machine
-p --poweroff Switch off the machine
--reboot Reboot the machine
-f --force Force immediate halt/power-off/reboot
-w --wtmp-only Don't halt/power-off/reboot, just write wtmp record
-d --no-wtmp Don't write wtmp record
--no-wall Don't send wall message before halt/power-off/reboot
See the halt(8) man page for details.
What about SYSTEMCTL?
In the beginning of this article we mentioned systemctl and we think it's time to say a few words about it. In most new distros you can use the command to shutdown and reboot the operating system. Here is a bonus bonus tip how to use it :)
# Use System Control to shutdown the operating system
$ systemctl poweroff
-----------------------------------------------------
# Use System Control to restart the operating system
$ systemctl reboot
We hope you enjoyed this article if that is so please rate this page with the stars bellow and subscribe to our YouTube channel.