This guide will demonstrate some of the most common ways of using the shutdown command in Linux.
Linux shutdown command
The shutdown command requires root permission to shut down or reboot the system. To use it, ensure that you have access to a user account that can perform administrative tasks. Learn how to grant non-root users sudo permission.
Basic command structure
Here’s the base command structure.
- <options>: Specifies the behaviour of shutdown command, for example, rebooting, power-off, etc.
- <time>: Specifies the time to perform the action defined.
- <message>: All the users will receive this message as a notification for the upcoming shutdown/reboot event.
Many modern distros replaced the original shutdown tool with a shutdown alias to systemctl. It’s still available only for compatibility reasons.
Shutting down the system
If no argument is provided, then shutdown will shut down the system 1 minute after the command run.
It’s also equivalent to the flag “-P” or “–poweroff”.
Cancelling scheduled shutdown
Whenever running a shutdown command, it will generally schedule the task a few minutes in the future. In the meantime, if necessary, we can cancel the task by running the following command.
The flag “-c” tells to cancel any scheduled shutdown/restart of the system.
Restarting the system
Despite the name, the shutdown command can reboot the system. To restart the system, use the flag “-r” or “–reboot”.
Scheduling a shutdown
As demonstrated earlier, the shutdown will schedule the task described one minute into the future. However, we can manually set the time of acting.
For example, the following shutdown command will shut down the system at 10:00 AM. Note that shutdown uses a 24-hour format in terms of timing.
Alternatively, we can schedule a system shutdown after a certain number of minutes. In the following example, the system is scheduled to shut down after 250 minutes.
Scheduling a restart
Similar to scheduling system shutdown, we can also schedule a system restart. The following command will schedule a system restart at 9:00 AM.
Alternatively, tell shutdown to restart the system after several minutes.
So far, we’ve seen how to schedule a shutdown/reboot. In many situations, it’s necessary to act immediately. There are two types of time values that shutdown supports for this purpose.
Shutdown supports “now” as a valid time. As the label suggests, the action will be carried out immediately.
If you insist on using a numeric value, then we can also describe “now” as “+0”. Basically, the shutdown will act after 0 minutes (immediately, in other words).
Broadcasting custom message
Whenever any shutdown command is issued, it will broadcast a message to the whole system. It’s designed to notify about the upcoming action to all the users currently logged in. By default, the shutdown command will send a message that looks something like this.
However, we can also send a custom message to all the users. To use a custom message, use the following command structure.
Note that whenever you want to broadcast a custom message, it must be accompanied by a specific time argument.
Here are a few examples of using custom messages with various shutdown/restart tasks.
$ sudo shutdown +5 "system shutdown."
$ sudo shutdown -c "operation cancelled"
Linux shutdown command is a simplistic tool. This guide demonstrates using the shutdown command to schedule shutdown and reboot with custom shutdown messages.
The shutdown man page describes all the available shutdown arguments in-depth.