Spread the love

About The Linux Shutdown Command

The Linux Shutdown Command is used to stop the operating system safely. Users logged in receive a message that the system will be shut down. The command allows the system to shut down immediately or according to a set period of time. In this tutorial you will learn the basic ways to use the shutdown command as well as the best practices in using it. In some of the newer distributions, the uptime command is associated with the system command systemctl. In addition we are going to explore how to reboot how to schedule reboots, how to warn logged in users and more.

What will we cover in this topic?

Basic Syntax Of The Linux Shutdown Command

Before we move on, let’s look at the basic syntax of the command.

shutdown [options] [time] [message]
Code language: Bash (bash)

This is the output of the man page:

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,
too.

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
allowed.
Code language: Bash (bash)

shutdown –help output

shutdown --help
shutdown [OPTIONS...] [TIME] [WALL...]

Shut down the system.

Options:
     --help      Show this help
  -H --halt      Halt the machine
  -P --poweroff  Power-off the machine
  -r --reboot    Reboot the machine
  -h             Equivalent to --poweroff, overridden by --halt
  -k             Don't halt/power-off/reboot, just send warnings
     --no-wall   Don't send wall message before halt/power-off/reboot
  -c             Cancel a pending shutdown

Code language: Bash (bash)

Basic practices for use

The first example will immediately shutdown the operating system without any warnings to the other users:

shutdown -h now
Code language: Bash (bash)

In this case if you are using a ssh connection it will be terminated immediately. In the next example shutdown is going to be postponed for two minutes:

# shutdown -h (time in minutes)
$ shutdown -h 2
Shutdown scheduled for Mon 2021-03-22 18:52:31 EET, use 'shutdown -c' to cancel.
Code language: Bash (bash)

Now as we see in the output we can use another option to cancel the request:

# cancel shutdown request
$ shutdown -c
Code language: Bash (bash)

After running shutdown -c we are not going to see another output but the above command shutdown -h 2 will be terminated. An alternative method to shutdown -h is shutdown + like the next example:

# Shutdown server after 10 minutes
$ shutdown +10
Shutdown scheduled for Mon 2021-03-22 19:04:53 EET, use 'shutdown -c' to cancel.
Code language: Bash (bash)

Now lets create a more practical example. We want to shutdown the server after 30 minutes and all users to be informed about our action.

# Shutdown the server after 30 minutes and inform logged users
$ shutdown +30 "The server will be shutdown for maintenance after 30 minutes please log out all of your sessions!"
Shutdown scheduled for Mon 2021-03-22 19:28:27 EET, use 'shutdown -c' to cancel.

Code language: Bash (bash)

We can do even one better than that lets say we want to inform all users that the server will be shutdown at a specific time:

# Shutdown the server at a specific time and message
$ shutdown -h 21:00 "The server will be shutdown for maintenance at 21:00 please log out all of your sessions!"
Shutdown scheduled for Mon 2021-03-22 21:00:00 EET, use 'shutdown -c' to cancel.

Code language: Bash (bash)
# Scheduled server restart
$ shutdown -h 21:00 "The server will be restarted for maintenance at 21:00 on 23-03-2021 please log out all of your sessions!" -r
Reboot scheduled for Tue 2021-03-23 21:00:00 EET, use 'shutdown -c' to cancel.

Code language: Bash (bash)

A fast reboot method without any warnings or a schedule can be performed with the command reboot:

# A immediate reboot method
$ reboot
Code language: Bash (bash)

A reboot can be forced like a physical reset button an a computer:

# A immediate forced reboot
$ reboot -f Code language: PHP (php)

Alternative commands For Linux Shutdown Command

Halt command syntax and examples

Another great command for shutting down a linux distribution is the halt command. Here is the basic syntax for halt:

halt [OPTION]
Code language: Bash (bash)

And the help for halt:

$ halt --help
halt [OPTIONS...]

Halt the system.

Options:
     --help      Show this help
     --halt      Halt the machine
  -p --poweroff  Switch off the machine
     --reboot    Reboot the machine
  -f --force     Force immediate halt/power-off/reboot
  -w --wtmp-only Don't halt/power-off/reboot, just write wtmp record
  -d --no-wtmp   Don't write wtmp record
     --no-wall   Don't send wall message before halt/power-off/reboot

See the halt(8) man page for details.

Code language: Basic (basic)

And for final alternative command you can use poweroff, here is the syntax:

poweroff [OPTION]
Code language: Bash (bash)

Poweroff command syntax and examples

And the help for poweroff:

$ poweroff --help
poweroff [OPTIONS...]

Power off the system.

Options:
     --help      Show this help
     --halt      Halt the machine
  -p --poweroff  Switch off the machine
     --reboot    Reboot the machine
  -f --force     Force immediate halt/power-off/reboot
  -w --wtmp-only Don't halt/power-off/reboot, just write wtmp record
  -d --no-wtmp   Don't write wtmp record
     --no-wall   Don't send wall message before halt/power-off/reboot

See the halt(8) man page for details.

Code language: Bash (bash)

Here is a 60 second video tutorial for easier adaptation on the above commands

What about SYSTEMCTL?

In the beginning of this article we mentioned systemctl and we think it’s time to say a few words about it. In most new distros you can use the command to shutdown and reboot the operating system. Here is a bonus bonus tip how to use it 🙂

# Use System Control to shutdown the operating system
$ systemctl poweroff
-----------------------------------------------------
# Use System Control to restart the operating system
$ systemctl reboot
Code language: Bash (bash)

We hope you enjoyed this article if that is so please rate this page with the stars bellow and subscribe to our YouTube channel.

Leave a Reply