Shutdown Linux

Shutdown Linux Using The Command Line

In this tutorial, we’re going to show you how to shut down your Linux computer using the command-line interface (CLI), aka Terminal.

The shutdown command is especially useful for Linux servers. It’s also useful if you’re writing a bash script or if you just prefer using the CLI instead of the GUI on your Linux distro.

This tutorial will work on any Linux distro, including Ubuntu, Linux Mint, CentOS, Fedora, Debian, etc.

So, open up the Terminal, or SSH into your server, and follow the instructions below.

You need to use the root user or use sudo with each command.

How to use the shutdown command on Linux

The basic syntax of the shutdown command is:

shutdown [OPTIONS...] [TIME] [MESSAGE...]

The [TIME] is used to delay the shutdown command (shutdown the system after a certain amount of time). It can be specified in the hh:mm format. You can use one digit for the hours too. You can also just use “+m” if you want to wait only a certain amount of minutes.

The [MESSAGE] is a message all other logged-in users see. It’s often used to let others know that the system will shut down and that they should save all their work.

Here are some of the useful [OPTIONS] you can use with the command:

  • H – Halt the machine
  • P – Power off the machine
  • -r – Reboot the machine
  • h – Equivalent to -P, overridden by -H
  • -k – Don’t halt/power off/reboot, just send warnings
  • -c – Cancel a pending shutdown

The most basic and often used example of the command is:

sudo shutdown -h now

This command will shut down the Linux system immediately.

5 Examples of the shutdown command on Linux

Here are some useful examples and use cases of the shutdown command:

Reboot your system

To reboot your system using the shutdown command, you just need to use the -r option:

shutdown -r now

Although a much easier way to reboot a Linux system is to just use the reboot command:

reboot

Schedule a shutdown at 4:15 pm with a message

To schedule a shutdown after work hours are over, at 4:15 pm (16:15), run the following command:

shutdown -h 16:15 "The server will shut down at 4:15pm, please save everything before leaving work."

Schedule a shutdown after 10 minutes

If you want to schedule a shutdown 10 minutes after running the command (giving you enough time to save everything), run the following command:

shutdown -h +10

Reboot the system after 5 minutes with a message

To reboot the system in 5 minutes and broadcast a message to all users, run:

shutdown -r +5 “The server will reboot in 5 minutes due to kernel upgrades. Please save your work.”

Cancel a scheduled shutdown

If you scheduled a shutdown command by mistake, you can cancel it with the -c option:

shutdown -c

You can combine all these examples/options and create a shutdown command of your own.

Now that you learned what the shutdown command can do, you can clearly see its usefulness.

Leave a comment

Your email address will not be published.

One thought on “Shutdown Linux Using The Command Line”