Linux Shutdown Command | Explained

The Linux operating system is managed with the Command-Line Interface, which controls the system to perform tasks like shutdown, halt, or reboot. Linux shutdown command helps us to shut down, reboot, and halt the system without corrupting the files. The system shutting down, rebooting, or halting is done by executing the “shutdown” command.

This guide will explain the shutdown command thoroughly with the following timeline:

Let’s start the guide!

What is Linux Shutdown Command?

The shutdown command has manifold usages. It can shut down/power off, reboot/restart, or halt the system. The usage of the shutdown command depends on the syntax provided below:

Syntax:

$ shutdown [options] [time] [wall-Message]

The syntax components are displayed below:

  • Options: Replace it with the desired shutdown command option.
  • Time: Specifies the time after which the shutdown command executes.
  • Wall-Message: Displays the message before the shutdown.

Options

There are several options available in the shutdown command, which increases the functionality of the shutdown command. The below-written options/flags are available in the shutdown command:

-H or–haltThis option halts the system’s CPU.
-P or –poweroffThis option is utilized to power off the machine (default option).
-r or –rebootTo reboot the machine.
-hThis option is used to power off the system, but if you want to not power off the system after executing the command, use the “shutdown –halt” command to override this option.
-kTo send a shutdown/reboot warning to the system.
–no-wallDo not send a message to logged-in users before any shutdown activity.
-cTo cancel a pending shutdown, use the “c” option.

For more details on the shutdown command, use its “–help” flag as follows: 

$ shutdown --help

Let’s get into the usage of the shutdown command.

How to Use the Linux shutdown Command?

The “shutdown” command in Linux is utilized to power off the system. You can use the shutdown in different ways mentioned below in the examples:

Example 1: Default Behavior

The shutdown command is used to turn off, reboot/restart, and halt the system. But the default behavior of the shutdown command is to shut down the system (without any option). The “p” option (shutdown) is the default option of the shutdown command. To shut down the system, we use the below three commands, which perform the same shutdown function:

Note: The shutdown will start after 1 minute, which is the default processing time for the shutdown command.

$ shutdown
$ shutdown -p

Example 2: Shutdown the System Immediately

As the shutdown command takes one minute delay to shut down the system. To immediately shut down the system, the below “shutdown” commands are used:

$ shutdown 0
$ shutdown now

Example 3: Schedule Shutdown

The major advantage of the shutdown command is the ability to allow the scheduled shutdown of the system. We can use the shutdown command to give the system delay to complete the installation and shutdown at a specific time or after a specific time interval. The shutdown time format is hh:mm where “h” display hours and “m” minutes.

To schedule shutdown after five minutes, use the below-mentioned command:

$ sudo shutdown +5

The shutdown can be scheduled at a specific time of the day by utilizing the shutdown command.

For shutting down at 5:00 PM, use the below-mentioned command:

Note: Use the 24-hour format to schedule the shutdown command.

$ sudo shutdown 17:00

Example 4: Display Custom Warning Text Before Shutdown

When you execute the shutdown command, it displays a message with the shutdown time. You can  display your custom message before the shutdown for all the logged-in users of the system using the shutdown command.

To display a custom message “Restarting for Installing Updates” before the five-minute shutdown, run the below command in the terminal:

$ sudo shutdown +5 "Restarting for Installing Updates"

You must specify the time to display a custom message before shutdown.

Example 5: Cancel the Scheduled Shutdown

For scheduled shutdown, we can cancel the shutdown by using the “c” option of the shutdown command. To cancel the scheduled shutdown after 5 minutes, use the following commands:

$ sudo shutdown +5
$ sudo shutdown -c

Example 6: Reboot the System

To reboot the system, the shutdown command is used. We can utilize the “r” (reboot) flag of the shutdown to reboot, immediately reboot, and schedule a reboot of the system.

To reboot a system, use any of the below commands:

$ sudo shutdown -r
$ sudo shutdown -reboot

To reboot the system immediately without the default one-minute delay, use any of the below commands:

$ sudo shutdown 0
$ sudo shutdown -r now

The shutdown command can also be used to schedule a reboot after a fixed time or at a fixed time of the day. To reboot after 5 minutes or reboot at 5:00 PM, use the following commands:

$ sudo shutdown -r +5
$ sudo shutdown -r 17:00

Example 7: Halt the System

The shutdown command allows you to halt the system processor (CPU) utilizing the “h” or “–halt” options. These options can halt the system, halt immediately, or halt at a specific time. To halt the system after the default one-minute time, use the following commands:

$ sudo shutdown -h

To halt the system immediately, execute any of the below-written commands in the terminal:

$ sudo shutdown -h now
$ sudo shutdown -h 0

To plan a halt after ten “10” minutes, utilize the following command:

$ sudo shutdown -h 10

The shutdown command to halt the system at 8:00 PM (20:00 hrs) is mentioned below:

$ sudo shutdown -h 20:00

The output shows the shutdown is scheduled for 20:00 hrs time.

End of this guide!

Conclusion

Linux shutdown command is used to shut down, reboot, and halt the system. This command is utilized to perform the shutdown/reboot/halt functions immediately, schedule to a specific time or at a specific time of the day, and display a custom warning text before the execution. Moreover, to cancel the scheduled shutdown, use the “shutdown -c” command.