Command Linux

What is the Linux shutdown Command?

In Linux, the shutdown command is dedicated to shutting down and restarting the system. It can also perform additional tasks like scheduled shutdown or reboot. It’s available on all the Linux distros. The shutdown command sends a notification to all the system’s running processes and active users at the time of action. It also prevents any new user from logging in. It’s a secure way of shutting down or rebooting the machine.

This guide will demonstrate some of the most common ways of using the shutdown command in Linux.

Linux shutdown command

The shutdown command requires root permission to shut down or reboot the system. To use it, ensure that you have access to a user account that can perform administrative tasks. Learn how to grant non-root users sudo permission.

Basic command structure

Here’s the base command structure.

$ shutdown <options> <time> <message>

Here,

  • <options>: Specifies the behaviour of shutdown command, for example, rebooting, power-off, etc.
  • <time>: Specifies the time to perform the action defined.
  • <message>: All the users will receive this message as a notification for the upcoming shutdown/reboot event.

Many modern distros replaced the original shutdown tool with a shutdown alias to systemctl. It’s still available only for compatibility reasons.

Shutting down the system

If no argument is provided, then shutdown will shut down the system 1 minute after the command run.

$ sudo shutdown

It’s also equivalent to the flag “-P” or “–poweroff”.

$ sudo shutdown -P

Cancelling scheduled shutdown

Whenever running a shutdown command, it will generally schedule the task a few minutes in the future. In the meantime, if necessary, we can cancel the task by running the following command.

$ sudo shutdown -c

The flag “-c” tells to cancel any scheduled shutdown/restart of the system.

Restarting the system

Despite the name, the shutdown command can reboot the system. To restart the system, use the flag “-r” or “–reboot”.

$ sudo shutdown -r

Scheduling a shutdown

As demonstrated earlier, the shutdown will schedule the task described one minute into the future. However, we can manually set the time of acting.

For example, the following shutdown command will shut down the system at 10:00 AM. Note that shutdown uses a 24-hour format in terms of timing.

$ sudo shutdown 10:00

Alternatively, we can schedule a system shutdown after a certain number of minutes. In the following example, the system is scheduled to shut down after 250 minutes.

$ sudo shutdown +250

Scheduling a restart

Similar to scheduling system shutdown, we can also schedule a system restart. The following command will schedule a system restart at 9:00 AM.

$ sudo shutdown -r 9:00

Alternatively, tell shutdown to restart the system after several minutes.

$ sudo shutdown -r +250

Immediate shutdown/restart

So far, we’ve seen how to schedule a shutdown/reboot. In many situations, it’s necessary to act immediately. There are two types of time values that shutdown supports for this purpose.

Shutdown supports “now” as a valid time. As the label suggests, the action will be carried out immediately.

$ sudo shutdown -r now

If you insist on using a numeric value, then we can also describe “now” as “+0”. Basically, the shutdown will act after 0 minutes (immediately, in other words).

$ sudo shutdown -r +0

Broadcasting custom message

Whenever any shutdown command is issued, it will broadcast a message to the whole system. It’s designed to notify about the upcoming action to all the users currently logged in. By default, the shutdown command will send a message that looks something like this.

However, we can also send a custom message to all the users. To use a custom message, use the following command structure.

$ sudo shutdown +250 "<custom_shutdown_message>"

Note that whenever you want to broadcast a custom message, it must be accompanied by a specific time argument.

Here are a few examples of using custom messages with various shutdown/restart tasks.

$ sudo shutdown -r +25 "kernel update"
$ sudo shutdown +5 "system shutdown."
$ sudo shutdown -c "operation cancelled"

Final thoughts

Linux shutdown command is a simplistic tool. This guide demonstrates using the shutdown command to schedule shutdown and reboot with custom shutdown messages.

The shutdown man page describes all the available shutdown arguments in-depth.

$ man shutdown

Happy computing!

Related Articles

Trả lời

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *

Back to top button