Linux Shutdown Command [with Examples]

Let me show you how to use the Linux shutdown command through practical examples with detailed explanations.

2
Linux Shutdown Command

Need to know how to shutdown your Linux system safely using command line or how to schedule shutdown at specific time? Here’s the answer!

The shutdown command in Linux brings the system down in a secure way. This involves cutting the power to the main components of the system using a controlled process. 

Related: 20 Basic Linux Commands for Beginners Explained with Examples

The shutdown command allows you to shutdown the system immediately, or schedule a shutdown using 24 hour format. When the shutdown is initiated, all logged-in users and processes are notified that the system is going down by the signal SIGTERM. In addition to, no further logins are allowed.

It’s important to mention that only root or user with sudo privileges can execute shutdown command.

Below is the shutdown command syntax in Linux:

shutdown [OPTIONS] [TIME] [MESSAGE]
  • OPTIONS – Shutdown options such as halt, power-off or reboot the system.
  • TIME – Specifies when to perform the shutdown process.
  • MESSAGE – Specifies a message which will be broadcast to all users.

The basic usage is easy. All you have to do is to run the shutdown command.

sudo shutdown
Linux shutdown Command Without Options

As you can see from the image above, the command will not shutdown your Linux system immediately. If no time argument is specified, +1 is implied, which means the shutdown process will be initiated in a minute from now, which is the default time interval.

How to Shutdown Linux System Immediately

To immediately shutdown the system, you can use +0 or its alias now after the shutdown command:

sudo shutdown now

How to Schedule Shutdown at Specific Time in Linux

You can also easily schedule Linux shutdowns to occur after a certain period of time or at a certain time.

The time argument can have two different formats. It can be an absolute time in the format hh:mm or relative time in the format +m where m is the number of minutes from now.

For example, if you want to schedule a shutdown at 10 AM, then use the following:

sudo shutdown 10:00
Schedule Shutdown at Specific Time in Linux

It’s important to remember that the Linux shutdown command follows a 24 hours format. Therefore, to schedule the system to shut down at 10 PM:

sudo shutdown 22:00
Schedule Shutdown at Specific Time in Linux

Let’s now schedule a system shutdown in 30 minutes from now:

sudo shutdown +30
Schedule Shutdown at Specific Time in Linux

How to Broadcast a Custom Message

To show the message to the people who are logged in to your server before the server goes down, type your message after the time argument.

The following example, will shutdown the system in 20 minutes from now and notify the users that system upgrade will be performed:

sudo shutdown +20 "System upgrade in 20 minutes. Save your work."

The above command shall flash the message to all other logged in users and give them 20 minutes before the system goes for shutdown.

How to Restart Linux System Immediately Using the shutdown Command

To restart your Linux system in a safe way, use the following command below:

sudo shutdown -r now

The -r option, which stands for reboot, requests that the system be rebooted after it has been brought down.

How to Schedule Restart at Specific Time Using the shutdown Command

Just like a shutdown, a restart can also be scheduled. For example, to schedule a restart for your system at 10 PM:

sudo shutdown -r 22:00
Schedule Restart at Specific Time in Linux

To schedule a system restart in 30 minutes from now:

sudo shutdown -r +30
Schedule Restart at Specific Time in Linux

Canceling the Shutdown

The scheduled shutdown can be canceled anytime using the -c argument:

sudo shutdown -c

The command will immediately cancel the specified scheduled time of shutdown or restart. Keep in mind that this command cannot be used if you are immediately shutting down your system with the now or +0 expression.

How Do I Check My Scheduled Shutdown in Linux?

Now you are probably asking yourself: Is there any way to check if a shutdown countdown has been activated? Yes, this can be achieved by using the command below:

date -d @`cat /run/systemd/shutdown/scheduled | head -n 1 | cut -c6-15`

For example, if you set your Linux system to be shutting down at 10 PM (sudo shutdown 22:00), the output of the above command will be:

Check Scheduled Shutdown in Linux

I agree, it’s probably not the most elegant solution, but it does the job.

Conclusion

I hope this article helped you learn how to use the Linux shutdown command and its options. It is also an effective and risk-free way to close all processes and power off the system.

Find out more about various options in shutdown in its command line manual page.

If you have any questions or feedback, feel free to leave a comment.

2 Comments

Leave a Reply

Your email address will not be published.

Latest from Linux Knowledge