In this tutorial, I’ll show you how to perform a Linux shutdown command step-by-step along with how to safely reboot your system.
Before We Get Started…
Let’s take a refresher course.
After all, in any task or work we do, proper fundamentals and foundation is key to delivering the best output.
The basic syntax, as shown below, are the shutdown Linux command options you have when initiating the shutdown process.
shutdown [OPTIONS] [TIME] [MESSAGE]
- [OPTIONS] – Referred to as the shutdown options you can choose from: halt, reboot, or power-off.
- [TIME] – Referred to as the time argument for specifying when the shutdown will begin
- [MESSAGE] – Referred to as a custom message you can type and broadcast to all logged-in users
Also, the shutdown command in Linux is available to root users or any other user with root privileges.
List of Commands Used
Before diving into any practical examples or how to use the shutdown command itself, the list of commands listed here will be a reference to help you understand what each symbol means.
-h – requests that the system is halted after shutting down
-p – requests that the system powers off after shutting down
-r – requests to reboot the system. You can use a time argument with this to specify the reboot like requesting the system to reboot within 5 minutes, for example
-c – requests to cancel the shutting down process.
-k – sends out a warning and disables the login but does not shut down the system
-f – requests a forced reboot
How to Use the Linux shutdown command
We’ll go through the shutdown command in Linux first in its basic form and then proceed to use various arguments such as custom message, shutdown options, and a time argument for detailed instruction.
Basic Shutdown Command
To use the shutdown command for Linux in its most basic form, simply type:
This will automatically initiate the shutdown. Since no argument was specified, your system is going to power off after 1 minute, which is the default system setting.
If you want to initiate the system shutdown immediately, you can type:
sudo shutdown now
With this message, the system is going to turn off immediately rather than run the 1-minute time default interval.
For safety purposes, using the sudo shutdown command is preferrable since this allocates time allowance for you to save any files or make any necessary last-minute checkups.
Using the [OPTIONS] Argument
Given that you have three shutdown options, you can easily specify which option is best for your system.
Adding “-r” to the shutdown command will reboot the system. All you have to do is simply type:
sudo shutdown -r
This will reboot the system with the 1-minute time default setting.
Adding “-h” to the shutdown command will halt the system. All you have to do is simply type:
sudo shutdown -h
Power Off Option
Adding “-p” to the shutdown command will power off the system. All you have to do is simply type:
sudo shutdown -p
Similarly, you can use the sudo shutdown -r, -h, or -p with “now” to prevent the system from using the 1-minute time default setting.
Using the [TIME] Argument
To use the shutdown command with the time argument, there are 2 formats you can go for. The 1st format is in the hh: mm format where “hh” represents the hours and “mm” represents the minutes. The 2nd format uses +m where m is the number of minutes from the current time.
Things to note: If you decide to initiate a system shutdown using the “hh: mm” format, take note this follows a 24-hour format.
If you want to initiate a shutdown at 9 AM then,
sudo shutdown 9:00
If you want to initiate a shutdown at 2 PM then,
sudo shutdown 14:00
If you want to initiate a shutdown 5 minutes from now then,
sudo shutdown +5
If you want to initiate a shutdown 2 hours from now then,
sudo shutdown +120
Remember that the “+m” time format asks you specify the minutes, so if you want to shut down your system after an hour or longer, you have to convert it into minutes first. Otherwise, you can use the “hh: mm” time format.
You can also use the time argument along with the options argument like:
sudo shutdown -r +30
sudo shutdown -h +20
Using the [MESSAGE] Argument
To use the shutdown command for the message argument, it’s just as similar and easy as the time argument.
To broadcast a custom message, simply type the message you want after “shutdown”
If you want to broadcast a message that informs all logged-in users of needed maintenance then,
sudo shutdown “please save any necessary files, we’ll undergo maintenance”
This message will be broadcasted to all logged-in users with a 1-minute time default setting.
You can also combine the message argument with both the time and options argument. Say for example you wanted to reboot the system 5 minutes from now because of a hardware upgrade.
sudo shutdown -r +5 “please save any necessary files, we’ll undergo maintenance in 5 minutes”
How to Cancel a Shutdown command
If you initiated the command to shut the power off or reboot the system and suddenly, you forgot to save your files, you can easily cancel the command.
There is a restriction though when using the cancel command: you cannot use a time argument when canceling it.
The basic command to use when canceling a shutdown is by adding “-c”
sudo shutdown -c
If you want to broadcast a message, simply follow the same format as the basic cancel command and type the message you want after it
sudo shutdown -c “system is going to cancel reboot”
Using the shutdown command is also a way of shutting off the system in a secure way. In addition, being able to notify any users ahead of time along with specifying the time make it easier and efficient to deliver this information virtually.
I hope this article along with the practical examples shown were able to help you understand how to use the shutdown command effectively and easily.