Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Shutdown and Reboot Linux Systems From the Terminal
In this article, we will discuss how to shut down and restart Linux systems from the terminal. The ability to shut down and restart a system from the command line can be useful in a variety of situations, such as when the GUI is unavailable or when automating tasks via Linux shell scripts.
Overview
Linux is a fairly robust operating system, and as such, rebooting Linux servers is rarely necessary. However, sometimes there are reasons why you need to restart your system. For example, if we are running Linux on our personal computer, restarting and shutting down the system could be a daily operation.
System Shutdown Commands
Various commands can restart or shut down a system, such as shutdown, reboot, halt, and poweroff. Since restarting or shutting down a system will kill all running processes, you must have root or sudo permission to run such commands.
Most modern Linux distributions have adopted systemd as their system and service manager. On systemd-managed systems, systemctl centrally controls system restart and shutdown. For example, let's look at those commands on an Ubuntu system
$ file /sbin/{halt,poweroff,reboot,shutdown}
/sbin/halt: symbolic link to /bin/systemctl
/sbin/poweroff: symbolic link to /bin/systemctl
/sbin/reboot: symbolic link to /bin/systemctl
/sbin/shutdown: symbolic link to /bin/systemctl
It might be a little surprising to learn that all of these commands are linked to the same command: systemctl. This is because the systemctl program uses a technique to change its behavior based on how it was invoked.
The shutdown Command
We can use the shutdown command to safely reboot or shut down a Linux system. The syntax of using the shutdown command is simple
shutdown [OPTIONS...] [TIME] [MESSAGE]
Common Options
Now let's look at the common options supported by the shutdown command. We can pass the -r option to reboot our system instead of shutting down the machine
# shutdown -r Shutdown scheduled for Thu 2022-01-19 11:56:50 IST, use 'shutdown -c' to cancel.
The -H option tells the shutdown command to halt the system
# shutdown -H Shutdown scheduled for Thu 2022-01-19 11:56:50 IST, use 'shutdown -c' to cancel.
The -P option (or no option) will power off the system completely
# shutdown -P Shutdown scheduled for Thu 2022-01-19 11:56:50 IST, use 'shutdown -c' to cancel.
Schedule a Shutdown Operation
Sometimes we don't want to shut down or restart the system in one minute. Instead, we can schedule the shutdown operation at a specific time. The shutdown command supports two different time formats for scheduling
Absolute time HH:MM format
Relative time +NumberOfMinutes format
For example, we can schedule a reboot of the system for 8:08 AM
# shutdown -r 08:08 Shutdown scheduled for Thu 2022-01-19 08:08:00 IST, use 'shutdown -c' to cancel.
Let's look at another example where we schedule a system shutdown in 30 minutes
# shutdown +30 Shutdown scheduled for Thu 2022-01-19 12:36:55 IST, use 'shutdown -c' to cancel.
If we want to shut down the system immediately, we can use +0 or a convenient alias, now
# shutdown now
Since Linux is a multi-user operating system, we might want to broadcast a message to all currently logged in users about the scheduled shutdown or restart
# shutdown -r +45 "Attention: This system will restart in 45 minutes!" Shutdown scheduled for Thu 2022-01-19 12:48:39 IST, use 'shutdown -c' to cancel. Broadcast message from root@server (Thu 2022-01-19 12:03:39 IST): Attention: This system will restart in 45 minutes! The system is going down for reboot at Thu 2022-01-19 12:48:39 IST!
Cancel a Scheduled Shutdown
In the above examples, we have scheduled a reboot or shut down operation. However, there are times when we might want to cancel a scheduled operation. For example, if a reboot or shutdown was scheduled by mistake, or if a critical update needs to be installed before the scheduled reboot. In such cases, we can use the shutdown -c command to cancel a scheduled operation.
# shutdown -c Broadcast message from root@server (Thu 2022-01-19 12:05:15 IST): The system shutdown has been cancelled at Thu 2022-01-19 12:05:15 IST!
This command will cancel any scheduled reboot or shut down operation and display a message confirming the cancellation.
Alternative Commands
Besides the shutdown command, several other commands can be used for system control
| Command | Action | Description |
|---|---|---|
reboot |
Restart | Immediately restarts the system |
halt |
Halt | Stops all processes but keeps power on |
poweroff |
Power off | Shuts down and turns off the system |
systemctl reboot |
Restart | Systemd command to restart |
systemctl poweroff |
Power off | Systemd command to power off |
Examples
# Immediate reboot reboot # Immediate shutdown poweroff # Using systemctl directly systemctl reboot systemctl poweroff
Key Points
Always ensure no critical processes are running before shutting down
Use
sudoif you don't have root privilegesThe
shutdowncommand is the safest option as it allows scheduling and cancellationAll shutdown-related commands on systemd systems are symlinks to
systemctl
Conclusion
The shutdown command provides flexible options for scheduling system shutdowns and reboots with proper user notification. Understanding these commands and their switches helps administrators control Linux systems safely and efficiently, whether for immediate shutdown or scheduled maintenance operations.
