In some cases, you must shut down or reboot your computer to apply updates, install a new application, migrations, or perform other operations. Linux provides the shutdown command to securely stop all the running processes on your server and to notify all the logged-in users about the shutdown operation.
In this tutorial, we will learn how to use the Linux shutdown command-line utility with practical examples.
Linux Shutdown Command
The shutdown command is used to securely shut down the system. Use this command in Linux for system shutdown either immediately or at a specific time. Shutdown can also be used to reboot your computer system.
When you run the Linux shutdown command-line tool, then all running applications are closed, active system processes are saved, and all currently logged-in users are notified about the shutdown operation. This command also prevents new users from logging in after the shutdown process starts.
The basic syntax of this command is as follows:
shutdown [option] [time] [message]
- option denotes the operation that you want to perform, such as power-off (default option), halt, or reboot.
- time denotes when to execute the command. You can use this parameter to schedule a shutdown or reboot.
- message denotes a comment or message that you want to broadcast to all the logged-in users.
Useful Shutdown Commands
Shutdown provides several options and variations that you can use to perform different options. The following table lists some of the most useful shutdown commands:
|Shuts down the computer in one minute.|
|Halts and turns off the system.|
|Reboots the system in one minute.|
|Halts and turns off the system at a specified time.|
|Shuts down your computer immediately.|
|Reboots the system at a specified time.|
|Reboots the system immediately.|
|Brings down the system and then powers it off.|
|Cancels a scheduled shutdown.|
How to Use Linux Shutdown Command
The following examples show you some of the most common usages of Linux shutdown command:
1. Shutdown After 1 Minute
This is the default behavior of the shutdown command. Use shutdown without any options to shut down the system after one minute:
2. Shutdown Now
To do an immediate shutdown, use the Linux shutdown command with now option.
sudo shutdown now
Instead of using the time to now, you can use +0 time option to down the system immediately.
sudo shutdown +0
On a systemd based Linux Distributions the shutdown now equivalent command is systemctl poweroff. In those systems, shutdown command is a symbolic link systemctl.
3. Shutdown at a Specified Time
Use the time argument with the shutdown command to turn off your computer at a specified time. The time argument can be used in two formats- specified time of the day in HH:MM format or +m where you can specify the number of minutes from the current time when the shutdown process will start.
To shut down the system at 10 AM, specify the time after the shutdown command:
sudo shutdown 10:00
To shut down your computer after five minutes from the current time, specify the five minutes in +5 format:
sudo shutdown +5
4. Shutdown Message
System administrators can notify users with a warning message about the system shut down.
To shutdown the system in 30 minutes with a broadcast message, use the following command:
sudo shutdown +30 "System is going under maintenance in 30 minutes"
5. Cancel a Scheduled shutdown
There may be a situation where you must cancel a scheduled shutdown. For example, suppose there is a planned release and you need to hold off the shutdown. In that case, you can cancel it using the -c option with the shutdown command and can also specify a custom wall message:
sudo shutdown -c "Ops needs the scheduled shutdown"
This command does not show any output on the screen.
Unfortunately in systemd system the systemctl command doesn't have a schedule or cancel the shutdown. Another option is to add cron to /run/systemd/shutdown/scheduled script.
6. Shutdown command to reboot
By default, the shutdown -r command reboots your system after one minute. To shutdown immediately and automatically reboot your system use the following command:
sudo shutdown -r now
7. Shutdown command to Schedule a Reboot
To schedule a reboot, use the time parameter with the following command as you do with the system shutdown:
sudo shutdown -r +10 “Rebooting for maintenance”
The shutdown command provides a help page that you can refer to know more about the shutdown command options:
sudo shutdown --help
Linux Shutdown Command Options
The following table some of the useful options that you can use with the shutdown command:
|Brings down your system and requests for a system reboot.|
|Sends a request to either halt or power off the system after bringing the system down.|
|Sends a request to halt the system after bringing the system down.|
|Sends a request to power off the system after bringing the system down.|
|Cancels any scheduled shutdown. You can not specify a time with this option, but you can broadcast a custom message for the system users.|
|Sends a warning message to the users and disables all system logins. It does not bring the system down.|
In this tutorial, we learned how to use the shutdown command to power down or reboot your Linux system. Shutdown provides various options that you can use to either shut down your system immediately or schedule a shutdown. This command can also be used to reboot your system. You can try these command options and examples in a test environment, but you should use them carefully in a production environment.