Shutting Down a Linux Server

In this post we will look at how to use the shutdown command through practical examples and detailed explanations of the most common shutdown options.

The shutdown command brings the system down in a secure way. When the shutdown is initiated, all logged-in users and processes are notified that the system is going down, and no further logins are allowed. You can shut down your system immediately or at the specified time.

Shutdown Command Syntax 

Before going into how to use the shutdown command, let’s start by reviewing the basic syntax.

The shutdown command expressions take the following form:

shutdown [OPTIONS] [TIME] [MESSAGE]
  • options – Shutdown options such as halt, power-off (the default option) or reboot the system.
  • time – The time argument specifies when to perform the shutdown process.
  • message – The message argument specifies a message which will be broadcast to all users.

On the recent Linux distributions shutdown is an alias to systemctl and it is available in the system only for compatibility reasons.

How to Use the shutdown Command 

Only the root and users with sudo privileges can use crontab command.

When used with no arguments, the shutdown command will power off the machine.

$ sudo shutdown

The shutdown process starts after 1 minute, which is the default time interval.

How to Shutdown the System at a Specified Time 

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

The following example will schedule system shutdown at 11 A.M, this assumes that your current system time is correct and relevant to it’s current location.

$ sudo shutdown 11:00

The following example will schedule system shutdown in 10 minutes from now:

$ sudo shutdown +10

How to Shutdown the System Immediately 

To shut down your system immediately you can use +0 or its alias now:

 $ sudo shutdown now

How to Broadcast a Custom Message 

To broadcast a custom message along with the standard shutdown notification type your message after the time argument.

The following example, will shut down the system in 30 minutes from now and notify the users that a hardware upgrade will be performed:

$ sudo shutdown +30 "Hardware upgrade"

It is important to mention that when specifying a custom message, you must specify a time argument too.

How to Reboot the System 

To reboot the system, use the -r argument:

$ sudo shutdown -r

You can also specify a time argument and a custom message:

$ shutdown -r +5 "Updating kernel"

The command above will reboot the system after 5 minutes and broadcast Updating kernel.

How to Cancel a Scheduled Shutdown 

If you have a scheduled shutdown and you want to cancel it you can use the -c argument:

$ sudo shutdown -c

When canceling a scheduled shutdown you cannot specify a time argument, but you can still broadcast a message that will be sent to all users.

$ sudo shutdown -c "Canceling the reboot"



Comments

Leave a Reply

Your email address will not be published. Required fields are marked *