Using the shutdown Command in Linux

In this guide, we will be showing you how to use the shutdown command on a Linux based system.

shutdown command in linux

The shutdown command is used to turn off, halt or reboot your Linux system safely and securely.

When you initiate a shutdown, all logged-in users will be notified that the system is about to go down.

All login operations are also blocked to stop users from being able to log in during the shutdown process.

During the shutdown process, all running processes will be sent a SIGTERM signal. This signal tells the program that it needs to begin its process of exiting.

Syntax of the shutdown Command

Before we show you how to use the shutdown command, let us first go into its syntax.

The shutdown command has three different arguments that it can take in. However, all three of these arguments are optional.

shutdown [OPTIONS] [TIME] [MESSAGE]
  • The options argument is used so you can issue different commands to the shutdown command. Using this you can tell it to power off, reboot or halt the system.
  • Using the time argument, you can tell the system when you want to perform the shutdown. You can either set an exact time or tell it to complete the event a specific number of minutes later.
  • Finally, the message argument allows you to set the message that the system will broadcast to the logged in users upon shutdown.

Using the shutdown Command

To utilize the shutdown command, you will need to either be the root user or a user with superuser privileges.

The easiest way to use the command is to use it without any arguments. Without any arguments, the command will default to powering off the system.

sudo shutdown

You will see a message like below printed to the terminal. This message tells you the scheduled time as well as how to cancel the planned action.

Shutdown scheduled for Wed 2020-06-24 10:42:37 BST, use 'shutdown -c' to cancel.

As we have not specified the time, the shutdown process will automatically be scheduled for 1 minute later. One minute is the default interval.

How to Shutdown the System Immediately

In some cases, you may want to immediately use the shutdown command to power off your device.

To achieve this, we need to specify a time. We can use +0, or its alias now.

Below is an example of the two different ways you can shut down your Linux device without any delay.

sudo shutdown +0
sudo shutdown now

Your system should now immediately power off.

Scheduling a Shutdown at a Specified Time

By using the time argument, it is possible to specify the time in which you want to shut down your device. The time parameter accepts two different time formats.

  • You can define an absolute time by using the HH:MM format. With this format, you set the hour and minutes for the shutdown to occur.
  • It is also possible to use a relative time by using the +m format. Using this, you can specify how many minutes from now to execute the shutdown.

For example, if you wanted to schedule the restart for 2 PM, you would use the following command.

sudo shutdown 14:00

Another example, if you wanted to execute the shutdown in 20 minutes from now, you can utilize a command like the following.

sudo shutdown +20

As you can see, scheduling a shutdown in Linux is a relatively simple process.

Defining a Custom Broadcast Message

Whenever a shutdown command is called, a message will be broadcast to all currently logged in users.

By using the third parameter, you can define the message that is broadcasted.

The only caveat to using this is that the time parameter must be defined.

For example, if we wanted to shut down the system in 1 hour from now and wanted to tell the users that it is due to a hardware upgrade, we can use the following command.

sudo shutdown +60 "Hardware Upgrade"

Remember that when you are typing in a message with spaces you must wrap it in double quotes (" ").

Rebooting a System using shutdown

To reboot the system using the shutdown command we need to make use of the -r option.

This option tells the command that we want to reboot instead of powering off the device.

sudo shutdown -r

You can combine this option with both the time and custom message arguments.

sudo shutdown -r 11:00 "Restarting System"

By using the command above, the system will be rebooted at 11 AM with the message “Restarting System” to be broadcasted.

Putting the System into a Halt

In some cases, you may not want to power off your device but want to shut off the CPU.

A halt differs from powering off the device in that a halt only involves stopping all CPUs on the system. A power-off consists in sending a command signal to the PSU to disconnect mains power.

To achieve this, you can put your system into a halt by using the -H or --halt option.

sudo shutdown -H

Like with other options, you can still use this with both the time and message arguments.

sudo shutdown -H +20 "Halting System"

Canceling a shutdown Event

If you have scheduled a shutdown event, it is possible to cancel it if you haven’t used the +0 or now time options.

To cancel a pending shutdown, you need to use the -c option.

sudo shutdown -c

When you cancel a shutdown, it is possible to still broadcast a message alongside it.

sudo shutdown -c "Shutdown event canceled"

You should now have a good understanding of how to utilize the shutdown command on a Linux/Unix based system.

Be sure to check out our other Linux command guides and Linux tutorials.

If you feel like we have missed out on something, then feel free to leave a comment below.

Leave a Reply

Your email address will not be published. Required fields are marked *