Introduction
All Linux users and system administrators need to know how to shut down the entire system safely. There are several options to do so, including scheduling a shutdown at a specific time, shutting down immediately, broadcasting a unique message, and so on.
In this tutorial, learn how to use the Linux shutdown command with examples.
shutdown Command Syntax
Before going into specific ways to shut down your Linux system, you should understand the basic syntax of the shutdown
command:
shutdown [options] [time] [message]
[options]
define whether you want to halt, power-off, or reboot the machine.[time]
specifies when you want the shutdown to perform.[message]
adds a message that announces the shutdown.
Note: If you need to reboot instead of shut down the system, refer to How To Restart Or Reboot Linux Server From The Command Line.
How to Use the shutdown Command
To use the shutdown
command on Linux systems, a root user or a user with sudo privileges is required.
If you use the command without additional arguments, running sudo shutdown
in a terminal window executes the shutdown in 60 seconds.
In the image below, see the output received after running the shutdown
command.
Shutdown With All Parameters
To view all parameters when shutting down the Linux system, use the following command:
sudo shutdown --help
The output displays a list of shutdown parameters, as well as a description for each.
How to Shut Down the System at a Specific Time
To schedule a shutdown, add the [time]
argument and specify when you want it to take place. There are two ways to shut down the system at a specific time – using the absolute or relative time format.
The absolute time follows the format hh:mm and allows you to schedule a shutdown at a specified time. The command follows the syntax:
sudo shutdown hh:mm
For example, to require a shutdown at 7 AM in the morning, the command is:
sudo shutdown 07:00
Alternatively, use the relative format (+m
) and schedule a shutdown in a defined number of minutes from the time you run the command. In that case, the command syntax is:
sudo shutdown +m
To shut down the system in 20 minutes, run:
sudo shutdown +20
How to Shut Down the System Immediately
As previously mentioned, running the shutdown command without any arguments prompts the system to shut down a minute after running the command. However, if you require an immediate shutdown, use:
sudo shutdown now
Another option would be to schedule a shutdown using the relative time format with the value 0, as in the command below:
sudo shutdown +0
How to Broadcast a Custom Message
Once you schedule a system shutdown, all users within the system receive a message notifying them of the shutdown. To add a custom message to the shutdown notification to inform the users what is about to take place.
You can add a [message]
only if the command also includes the [time]
attribute:
sudo shutdown [time] "[message]"
For instance, to shut down the system in 20 minutes and broadcast the message System Upgrade, run:
sudo shutdown +20 "System Upgrade"
Note: Another way to broadcast messages to users in Linux is via the wall command.
How to Cancel a Scheduled Shutdown
To cancel a scheduled shutdown, use the command:
sudo shutdown -c
You can also add a message to notify users that the shutdown is canceled. To do so, add the [message]
option (within quotations) to the command above. For example:
sudo shutdown -c "Canceling System Upgrade"
Conclusion
This article includes all the basic shutdown
commands every Linux user should know. Utilizing this command is a safe way to shut down your system. Also, it is a useful method of informing all users about scheduled shutdowns.
原创文章,作者:306829225,如若转载,请注明出处:https://blog.ytso.com/224203.html