How to Use the Linux Shutdown Command in Ubuntu and CentOS
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 use the shutdown safely, reboot, hibernate your VPS using Linux commands.
We’ll walk you through the process using two different Linux distributions: CentOS and Ubuntu 22.04.
Every operating system requires a shutdown or reboot to keep things running as they should. Shutting down a server via the command line is a secure method because it notifies all logged in users that the system is about to be turned off.
Here, you’ll even learn how to trigger the OS to power off on a schedule using Linux commands.
A Brief Overview of the Linux Shutdown Command:
Required Knowledge | Basic Linux commands, Terminal usage |
Privileges Required | Root |
Difficulty | Beginner |
Main Goal | Shutdown, Reboot, and System Power Management |
OS Compatibility | Linux Distributions, Unix-like Systems |
What Is the Shutdown Command
The shutdown command in Ubuntu and CentOS lets you power off, reboot, and halt your system. Below is the command syntax that is used to shutdown and restart the machine.
Shutdown [OPTIONS] [TIME] [WALL]
The shutdown command can also reboot, halt, or power off your system.
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.
Shutdown Command Examples in Linux and CentOS
Now let’s go over some basic shutdown command usage in Linux and CentOS.
How to Use 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
As 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.
How to Restart Your VPS using the Shutdown Command in Linux
To restart or reboot your PC safely, 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.
How to 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!
Discover Other Linux Commands for Server Management
How to Check Disk Space on Linux
How to Transfer Data With Curl Command
How to Calculate Process Execution With Time Command
How to Transfer Files Using Scp Command
How to Monitor Changes With Watch Command
How to Transfer and Synchronize Data With Rsync
How to Manage and List Services in Linux
How to Kill a Process in Linux