shutdown command in Linux


In Linux, the shutdown command is an essential tool for system users as well as administrators, providing a safe/controlled method for turning off or rebooting a system. This command greatly enhances system management and ensures that processes are terminated gracefully, without causing data loss or corruption.

The Linux shutdown command is a versatile tool that allows system administrators to safely turn off a computer from the command line. It’s particularly useful in situations where a graphical user interface is not available, such as on servers or when accessing remote systems via SSH.

This article gives a comprehensive guide on “shutdown” commands in Linux with all possible examples.

Shutdown command in Linux

Linux shutdown command effectively ensures that you can manage system power states responsibly, whether you’re an experienced system administrator or a new Linux user. To use the shutdown command in Linux with all its options, follow below:

Syntax and Options

The general syntax of the shutdown command is as follows:

shutdown [options] [time] [message]

[options] can be used to power off, reboot, or halt the machine.

Some of the options are given below:

options Description
-r Reboot after shutdown.
-h Halt the system; can be used in conjunction with `-P` to power off the system.
-H Put the system into hibernation.
-P Power off the system.
-c Cancel a scheduled shutdown.
-k Send a warning message to all logged-in users without actually shutting down the system.

[time] specifies/identifies when the shutdown happens/occurs. Some are given below:

time Description
now Shutdown immediately.
+m Schedule the shutdown in ‘m’ minutes. (relative time)
hh:mm Schedule the shutdown at a specific time. (absolute time)

[message] allows for a custom notification/message to be broadcast to all logged-in users.

Let’s move forward to the practical implementations.

Use of shutdown Command in Linux

The “shutdown” command is a strong/efficient tool utilized for safely turning off or rebooting in a Linux system. It can be executed with various options to set/specify the behavior required. Let’s explore the “shutdown” command in Linux:

Example 1: Immediate Shutdown

To execute a shutdown, one must have root or sudo privileges. To shut down the Linux system immediately, the command is:

sudo shutdown now

Alternatively, use the “shutdown” with the “+0” option:

sudo shutdown +0

This initiates an immediate shutdown process.

Remember: Without additional arguments, “sudo shutdown” initiates a shutdown sequence that will occur after 60 seconds.

Example 2: Scheduled Shutdown (Using Absolute Time)

Scheduling a shutdown at a specific time can be done using the absolute time format “hh:mm”. For instance, use the below syntax:

sudo shutdown hh:mm

For example, to set a shutdown at 7:00 AM, users use:

sudo shutdown 07:00

This shutdowns the computer at 07:00 AM.

Example 3: Scheduled Shutdown (Using Relevant Time)

To schedule a shutdown in a certain number of minutes from the current time, use a relative format “+m” (where “m” is the number of minutes to wait) as below:

sudo shutdown +m

For instance, shutdown the Linux system in 20 minutes using the “+20” utility:

sudo shutdown +20

It shut down the system within 20 minutes of the command’s execution.

Example 4: Custom Shutdown Message

It’s also possible to broadcast a custom message to all logged-in users to notify them of the impending shutdown by including a “[message]” alongside the “[time]” argument.

To broadcast a custom message along with the shutdown notification, include the message after the time argument. Let’s shut down the system after 10 minutes along with messages:

sudo shutdown +10 "System maintenance in 10 minutes."

This shutdowns the system in 10 minutes with a custom warning message. This notifies users of the impending shutdown and the reason for it.

Example 5: Reboot System

To reboot the system now, use the “shutdown” with the “r” option for rebooting:

shutdown -r now

It reboots the system.

Example 6: Cancel a Scheduled Shutdown

If there’s a need to cancel a scheduled shutdown, the “shutdown” command can be used with the “-c” option:

sudo shutdown -c

It’s important to note that the “shutdown” command requires superuser privileges, so it typically needs to be run with “sudo”.

Viewing Help and Parameters

To view all parameters and options available with the shutdown command, use:

sudo shutdown --help

This displays a list of all parameters and briefly describes each.

Note: Check the system time to ensure the scheduled shutdown or reboot occurs at the correct time.

Bonus Tip: Alternatives of shutdown Command in Linux

Alternatives to “shutdown” include the “halt”, “power off”, and “reboot” commands, which are effectively shortcuts to the “systemctl” command in system-based distributions.

These commands ensure compatibility with System V init-based systems and can perform shutdowns, reboots, and system halts depending on the options used.

For detailed guides, users can navigate/refer to guides that are given/available online.

Conclusion

In Linux, the shutdown command can be used via the “sudo shutdown”. It initiates a shutdown sequence that will occur after 60 seconds. However, the command “sudo shutdown now” or “sudo shutdown +0” is used for immediate shutdown.

For best practices, always notify users in advance before scheduling a shutdown or reboot, especially on multi-user systems, on production systems, to avoid unintended service disruptions.

This comprehensive guide has explained all possible examples of shutdown commands in Linux.

Print Friendly, PDF & Email
Categories