How to Use the Linux Shutdown Command in Ubuntu 18.04 and CentOS 7

Most of the popular Operating systems out there allow you to shut down your PC or laptop with different methods. Linux operating systems also has ways for a user to safely shutdown, reboot, hibernate or suspend your Unix based machine. In this tutorial, we’ll show you how to safely use the shutdown, reboot, hibernate your hosted virtual server using Linux commands.

We’ll walk you through in two different Linux flavors – CentOS 7 and Ubuntu 18.04.

Shutting down or rebooting server is important for every operating system for keeping things working as intended. Shutting down server through the command line is a secure way as it notifies all the logged in users that the system is about to go off.

Here you’ll even learn how to trigger the OS to power off on a schedule.

Shutdown Command in Linux Ubuntu and CentOS

The shutdown command in Ubuntu and CentOS lets you power off, reboot, and halt your system. Below is the command syntax that is being used to shutdown and restart the machine.

Shutdown [OPTIONS] [TIME] [WALL]

The shutdown command can to reboot, halt, or power off.

The first argument of [OPTIONS] can be a time string. After the argument, optionally you can type in a wall message to notify the logged-in users before shutting down your system.

The format for the time string is hh:mm (hour/minute) – a 24-hour time format. This will specify the time to execute the shutdown command. Alternatively, you can use +m where m indicates minutes. It will instruct the machine to shutdown in the number of minutes you want.

You can also use now in the syntax which is an alias for +0, this will trigger an immediate shutdown of your VPS. If you don’t specify the [time] argument, Linux as default implies +1 before shutting down.

Bear in mind that a time argument is a must if you want to specify a wall message. The /run/nologin file will be created 5 minutes before the system shuts down only if you have implied a time argument to ensure that further logins are not to be allowed.

Using the Shutdown Command in Linux Ubuntu and CentOS

The shutdown command for Ubuntu and CentOS is relatively similar. Each command shown below can be used in its dedicated Terminal. Remember, that you’ll have to use SSH to access your VPS. We have a tutorial covering the process with PuTTY!

The basic shutdown command for both CentOS and Ubuntu looks like this:

shutdown

The command above will not shut down your PC immediately, it will set a one-minute timer before shutting down. Remember to save your work before the shutdown takes place.

To shut down your PC immediately type in the following command and hit enter:

shutdown now

Like we mentioned before, here the command for both OS is the same.

To shut down your PC at a dedicated time, type in the following command into the command line and hit enter:

shutdown hh:mm

The Linux shutdown command follows a 24 hours format so type in hours instead of hh and minutes instead of mm.

To shut down after a few minutes or hours, type in the following command and hit enter:

shutdown +m

Remember, here m indicates minutes. Just specify the number of minutes.

To show a message to the people who are logged in your VPS type in the following command and hit enter:

Shutdown +m “Please save your Work, the PC will Shutdown in 5 Minutes”

Here the text in quotes can be whatever message you’d like.

Restart Your VPS using the Shutdown Command in Linux

To restart or reboot your PC in a safe way, use the following command below:

shutdown –r

The command won’t reboot your machine immediately, it will set a one-minute timer before rebooting. For this, you can save your work before reboot takes place.

To restart your PC immediately, just add the now option, as you did previously.

shutdown –r now

To schedule a restart for your system, type in the following command and hit enter:

shutdown –r hh:mm

To restart after few minutes or hours, type in the following command and hit enter:

shutdown –r +m

Remember, here m indicates minutes. Just specify the number of minutes.

To show the message to the people who are logged in with your server before the it goes down, type in the following command and hit enter:

Shutdown –r +m “Please save your Work, the PC will restart in 5 Minutes”

Here are some additional Linux shutdown command options you should be familiar with:

  • -poweroff, -P : like halt Powers off the system (also turns off unit)
  • -reboot, -r : Reboot the system.
  • -halt, -h : Halt the machine after terminating processes.

You can also shut down the using the halt and power off options using the following command

shutdown –h

For powering off use:

shutdown –p

In the above commands, you can also specify the time and then wall message after the option argument.

Cancel a Scheduled Shutdown Command in Linux

To cancel a Scheduled shutdown or a restart of your PC, you can simply type in the following command before you reach the dedicated time of the scheduled shutdown of your PC.

shutdown –c

These commands will immediately cancel the specified scheduled time of shutdown or restart. You cannot use this command If you used +0 or now.

Conclusion

That’s it, hope this article helped you learn how to use the Linux shutdown command and its options. If you faced any confusion in the tutorial, please let us know so we can resolve it for you!

Author
The author

Edward S.

Edward is a content editor with years of experience in IT writing, marketing, and Linux system administration. His goal is to encourage readers to establish an impactful online presence. He also really loves dogs, guitars, and everything related to space.