shutdown command in Linux with Examples
The `shutdown` operation in Linux is a crucial command for managing system power states, allowing administrators to halt safely, power off, or reboot the system. This command provides flexibility in scheduling downtimes, ensuring minimal disruption to users and processes. In this article, we will explore the `shutdown` command with practical examples, illustrating how to use its various options to control system behavior effectively.
What is a Shutdown in Linux?
The shutdown command in Linux is used to shut down the system safely. You can shut down the machine immediately, or schedule a shutdown using 24 hour format. It 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. Only root user can execute shutdown command.
Syntax:
shutdown [OPTIONS] [TIME] [MESSAGE]
- OPTIONS: Various options to control the shutdown process, such as halting, powering off, or rebooting the system.
- TIME: Specifies when to perform the shutdown, either immediately, after a specified delay, or at a specific time.
- MESSAGE: An optional message that is broadcasted to all logged-in users, informing them of the scheduled shutdown.
Key Options of the Shutdown Command
The following are the options of shutdown command in Linux:
‘-r’: Requests that the system be rebooted after it has been brought down.
‘-h’: Requests that the system be either halted or powered off after it has been brought down, with the choice as to which left up to the system.
‘-H’: Requests that the system be halted after it has been brought down.
‘-P’: Requests that the system be powered off after it has been brought down.
‘-c’: Cancels a running shutdown. TIME is not specified with this option, the first argument is MESSAGE.
‘-k’: Only send out the warning messages and disable logins, do not actually bring the system down.
How to use the ‘shutdown’ command?
The shutdown
command in Linux is used to halt, power off, or reboot the system. It can be scheduled or executed immediately, providing flexibility in managing system downtime.
Syntax:
shutdown [OPTIONS] [TIME] [MESSAGE]
Basic Common Shutdown Commands
1. Immediate Shutdown
The following command is used for shutdown immediately:
sudo shutdown now
2. Broadcasting Custom Messages
The following command is used for scheduling a shutdown:
sudo shutdown +10 "System will shut down in 10 minutes"
3. Canceling a Scheduled Shutdown
The following command is used for canceling a shutdown operation:
sudo shutdown -c
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 a system shutdown at 5 A.M.:
sudo shutdown 05:00
The following example will schedule a system shutdown in 20 minutes from now:
sudo shutdown +20
How to shutdown the system immediately?
To shutdown your system immediately you can use +0 or its alias now:
sudo shutdown now
How to broadcast a custom message?
The following command will shut down the system in 10 minutes from now and notify the users with message “System upgrade”:
sudo shutdown +10 "System upgrade"
It is important to mention that when specifying a custom wall message you must specify a time argument too.
How to halt your system?
This can be achieved using the -H option with the shutdown command:
shutdown -H
Halting means stopping all CPUs and powering off also makes sure the main power is disconnected.
How to make shutdown power-off machine?
Although this is by default, you can still use the -P option to explicitly specify that you want shutdown to power off the system.
shutdown -P
How to reboot using shutdown?
For reboot, the option -r is used with shutdown for exection:
shutdown -r
You can also specify a time argument and a custom message:
shutdown -r +5 "Updating Your System"
The command above will reboot the system after 5 minutes and broadcast Updating Your System”.
How to cancel a scheduled shutdown?
If you have scheduled a 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"
shutdown command in Linux – FAQs
What is the shutdown command for Linux?
The `shutdown` command is used to power off, halt, or reboot the system.
What is the `shutdown -H` command in Linux?
The`shutdown -H now` command halts the system immediately, stopping all processes without powering off the hardware.
How do I shut down my Linux system via the terminal?
Use`sudo shutdown now` to shut down immediately or `sudo shutdown +10` to schedule a shutdown in 10 minutes.
What are the shortcut keys for shutting down Linux?
Common shortcuts include `Ctrl + Alt + Del` for rebooting or custom shortcuts set in the desktop environment.
How do I check shutdown logs in Linux?
Use`last -x | grep shutdown` to check shutdown and reboot logs.