In this guide, we will be showing you how to use the shutdown command on a Linux based system.
The shutdown command allows you to safely and cleanly shutdown your Linux system and is the recommended way to do so.
This tool has versatility, allowing you to perform various actions beyond just powering off your device.
It even allows you to print a message to all users alerting them that a shutdown, restart, or halt will occur.
There are a couple of other commands that perform similar functions, such as poweroff, halt, and reboot. However, we will go over each of those in their own guide.
Over the next couple of sections, we will show you how to use the shutdown command in Linux.
Please note that you will need to have a user that has superuser privileges to use this command. If your user is not the root user, you will need to use “sudo
” in front of the shutdown command.
Table of Contents
- Syntax of the shutdown Command
- Basic Usage of the shutdown Command
- Shutdown the System at a Specific Time
- Powering off the System Immediately
- Broadcasting a Message on Shutdown
- Restart your Linux System using the shutdown Command
- Halting the System with the shutdown Command
- Canceling a Scheduled Shutdown
- Conclusion
Syntax of the shutdown Command on Linux
Before we show you how to use this tool, let us explore the syntax of the shutdown command on Linux.
Below you can see how the command is expressed within Linux, showing all three of its optional parameters.
shutdown [OPTIONS] [TIME] [MESSAGE]
When used without any options the default behavior of this tool is to shutdown the device after 1 minute.
Using the optional parameters we can control the behavior of Linux’s shutdown command.
[OPTTIONS]
– This parameter allows you to control the command’s behavior.
You can use this to change the tool, so it performs a restart or halt instead of powering off your device.[TIME]
– Using the time parameter, you can set the time in which the shutdown command will execute.
For example, if you want to shut down the system after 10 minutes have passed, you can use+10
.[MESSAGE]
– The final parameter supported by this tool allows you to choose a message you want to broadcast.
Any users connected to the system will see this message. Please note that the[TIME]
parameter is required when setting a message.
Basic Usage of the shutdown Command
The most basic usage of the shutdown command on Linux is to use it without any parameters.
When you use this tool without any parameters, it will assume that you want to power off your device. Additionally, Linux will schedule the shutdown for one minute from when you ran the command.
Using the command in this way is great when you only want the device to be shut down and don’t need it to occur immediately.
shutdown
After running the shutdown command, Linux will show a message on the command line. This message tells you when a shutdown is scheduled and how you can stop it.
Shutdown scheduled for Sat 2022-05-07 07:39:49 EDT, use 'shutdown -c' to cancel.
Shutdown the System at a Specific Time on Linux
One of the core features of the shutdown command is its ability to shut down your Linux system at a specified time.
This tool allows you to specify this as an absolute time using the format “hh:mm
” or a relative one using the format “+m
“.
shutdown TIME
Let us quickly go over the formats you will be using for the time parameter.
hh:mm
– The “hh
” part of this format allows you to specify the hour. This hour is specified in 24-hour time and is expressed as two digits.
The “mm
” part is the minutes of that hour, this needs to be expressed as a two-digit number.
For example, 11:35pm would be written as “23:35
“.+m
– The time specified for this format is the minutes from the current time you want the shutdown to occur.
For example, to perform the shutdown in 10 minutes, you would use “+10
“.
Example of Setting a Specific Time to Shutdown
For this example, let us use the Linux shutdown command to power off our device at 1:37pm.
To achieve this, we need to use “shutdown
” followed by the time expressed in the 24-hour format. In our case, this means our time will be written as “13:37
” and not “1:37
“.
shutdown 13:37
Example of Using a Relative Time with the Shutdown Command
The shutdown command allows you to set a time relative to the current time by using the “+
” operator.
For this example, let us use this command so that our device will be powered off 25 minutes after you run the command.
We need to use “shutdown
“, followed by the plus (+
) symbol, and finally, the number 25
.
shutdown +25
Powering off the System Immediately with the shutdown Command
If you don’t want to wait, the shutdown command allows you to immediately power off your Linux-based system.
There are two ways that you can achieve this that we will go over.
First, you shut down your system immediately by setting the relative time to “+0
“.
shutdown +0
Alternatively, there is an alias that you can use instead. If you use “now
” in the time parameter, the system will be powered down immediately.
shutdown now
Please note that you cannot set a message if you shut down the system immediately.
Broadcasting a Message on Shutdown
You can control the message broadcast to your Linux system when the shutdown command is executed.
This message is called the “wall” and is set by utilizing the third parameter. You can only set a message when the time parameter has been utilized.
shutdown TIME MESSAGE
For example, we would use the following command if we want to shut down our Linux system after 10 minutes have passed and broadcast the message “System Upgrade
“.
shutdown +10 "System Upgrade"
If your message contains any spaces, it must be wrapped in double-quotes (" "
).
Restart your Linux System using the shutdown Command
Even though this command is called “shutdown”, this tool can perform other actions, including restarting your Linux device.
You will need to either use the “-r
” or “--reboot
” option to achieve this. This option tells the command that it should perform a reboot rather than a “power-off” of your machine.
shutdown -r
You can also use the time and message parameters when using the restart option.
For example, you can use the following command if you want to restart after 10 minutes have passed and broadcast the message “Restarting for Kernel Upgrade
“.
shutdown --reboot +10 "Restarting for Kernel Upgrade"
Halting the System with the shutdown Command
You can also use Linux’s shutdown command to halt the currently running system. The difference between a halt and a poweroff is quite distinct.
When a system is halted, it will not completely power off. Instead, it will only stop the operating system and return to the bios.
You can initiate a halt in Linux by using the “-H
” and “--halt
” options alongside the shutdown command, as shown below.
shutdown -H
Like with the power off and restart options, you can also use the time and message parameters with this option.
For example you can utilize the following command, to halt the system after 5 minutes have passed.
shutdown --halt +5
Canceling a Scheduled Shutdown
You can cancel any shutdown event you have scheduled using this command before they are run.
To cancel a scheduled event, you will need to use the “-c
” option alongside the “shutdown
” command.
shutdown -c
The cancel option also allows you to broadcast a message. Setting a message is helpful if you want users to know why you canceled the shutdown.
For example, if you want the user to be told a hardware upgrade has been postponed, you can utilize the following command.
shutdown -c "Hardware Upgrade has been postponed"
Conclusion
In this tutorial, we have shown you how to use the shutdown command on your Linux system.
You can perform other actions than just powering off your device despite the command name. This includes halting or restarting your Linux device.
If you have any questions about using this command, please comment below.
Please check out our many other Linux command guides to learn more about the Linux operating system.