Linux shutdown Command Explained with Examples
The Linux command line may be a bit hard to learn, but it's worth it. Reason being, it's so powerful that you can do almost everything with it that you can otherwise do using UI. At HowtoForge, we have already discussed a plethora of command line tools (that let you do different kind of operations), and here, in this tutorial, we will discuss a utility which you can use to shut your system down.
The utility in question in shutdown. In this tutorial, we will discuss the basics of this tool using some easy to understand examples. But before we do that, it's worth mentioning that all examples here have been tested on Ubuntu 16.04 LTS.
Linux shutdown command
The shutdown command lets you power-off, halt, or reboot your system. Following is its syntax:
shutdown [OPTIONS...] [TIME] [WALL...]
And here's how the man page describes it:
shutdown may be used to halt, power-off or reboot the machine.
The first argument may be a time string (which is usually "now").
Optionally, this may be followed by a wall message to be sent to all
logged-in users before going down.
The time string may either be in the format "hh:mm" for hour/minutes
specifying the time to execute the shutdown at, specified in 24h clock
format. Alternatively it may be in the syntax "+m" referring to the
specified number of minutes m from now. "now" is an alias for "+0",
i.e. for triggering an immediate shutdown. If no time argument is
specified, "+1" is implied.
Note that to specify a wall message you must specify a time argument,
If the time argument is used, 5 minutes before the system goes down the
/run/nologin file is created to ensure that further logins shall not be
Following are some Q&A-styled examples that should give you a good idea on how the shutdown utility works:
Q1. How to use shutdown?
The basic usage is easy - all you have to do is to run the 'shutdown' command.
The default behavior of this tool is to power off the machine. Please note that if no time argument is specified, +1 is implied, which means the power off process will be initiated in a minute from now. In case you want the system to power off immediately, you can use now or +0.
In case you want to issue a wall message (to sent to all logged-in users before going down), you can do that in the following way:
shutdown 'YOUR MESSAGE HERE'
Q2. How to halt machine using shutdown?
This can be achieved using the -H option.
In case you aren't aware, there's a difference between halting and powering off a system. While the former involves stopping all CPUs, the latter also makes sure the main power is disconnected.
Q3. How to make shutdown power-off machine?
Although this is by default, you can still use the -P option to explicitly specify that you want shutdown to power off the system.
Q4. How to reboot using shutdown?
For reboot, the option is -r.
Q5. How to make shutdown only write wall message, or vice-versa?
In case you just want shutdown to shoot wall messages, without performing a halt, power-off, or reboot, use the -k command line option.
Q6. How to cancel a pending shutdown?
You can use shutdown to schedule a halt, power off, or reboot. For this, all you have to do is to pass the time at which you want the process to start. For example:
shutdown -r 18:00
However, in case you want to cancel a scheduled shutdown, you can do that as well. This can be done using the -c command line option.
As most of you'd agree, the shutdown command doesn't have a steep learning curve. Most features/options it offers are easy to understand and use. Here, in this tutorial, we have discussed the majority of options. After you're done practicing these, you can learn more about the tool by heading here.