In this article, we will study the eight Linux shutdown commands with examples.
Also Read: 5 Best Linux Distros for Gamming
Linux Shutdown Command Tool
shutdown [OPTION]… TIME [MESSAGE]
Besides OPTION & TIME, the above syntax states that we can also print a MESSAGE in the command line through these commands.
Options used in the shutdown commands
-r: Request the system to reboot after being brought down.
-h: Request the system to freeze or shut down after being brought down.
-H: Request the system to an only halt after being brought down.
-P: Request the system to power off after being brought down.
-c: To cancel a running shutdown after being brought down.
-k: To send a warning message and disable the logins. (will not actually bring the system down.)
Note: We need root privileges for these command executions.
1. The Basic Linux Shutdown Command
The shutdown command can also be used in the following basic form.
$ sudo shutdown 5 [sudo] password for admin:
Broadcast message from admin@dev-db (/dev/pts/2) at 19:44 ...
The system is shutting off for maintenance in 5 minutes!
2. Initiating Reboot Through -r option.
The command -r
can also be used to reboot the system through the shutdown command.
$ sudo shutdown -r 5
Broadcast message from admin@dev-db (/dev/pts/2) at 19:49 ...
The system is shutting off for reboot in 5 minutes!
3. Initiating Power off/halt using -h option.
Once the -h option is initiated, the system will decide whether or not to shut down or halt the system.
$ sudo shutdown -h 5
Broadcast message from admin@dev-db (/dev/pts/2) at 19:51 ...
The system is shutting off for halt in 5 minutes!
4. Insisting the System to Shut Down using -P option.
We can let the user insist that the system power off once by using the -P option.
$ sudo shutdown -P 5
Broadcast message from admin@dev-db (/dev/pts/2) at 19:53 ...
The system is Insisted to power off in 5 minutes!
5. Linux Shutdown Command to Print a Message.
Through the Linux Shutdown Command, the user can also print a custom message, so for example, the user and the admin can use these custom messages to convey all the country users a reason to shut the system down.
$ sudo shutdown 5 "System is shutting down to install new updates"
Broadcast message from admin@dev-db (/dev/pts/2) at 19:56 ...
The system is shutting off for maintenance in 5 minutes!
System need to shut down to install latest updates.
6. Insisting the System to Halt using -H Option.
-H option provided by the shutdown command can let the user or/and admin insist the system halt once initiated.
$ sudo shutdown -H 5
Broadcast message from admin@dev-db (/dev/pts/2) at 19:58 ...
The system is initiating for halt in 5 minutes!
7. Using -c to Cancle the Shutdown Operation.
If the shutdown command needs to be cancelled for any scenario, you can set the time in the prompt and initiate the cancellation using the -c
command.
$ sudo shutdown -c
The below way shows the command in a separate window shell affecting the shutdown.
$ sudo shutdown 5
Broadcast message from admin@dev-db (/dev/pts/2) at 19:59 ...
The system is initiating down for maintenance in 5 minutes!
Shutdown cancelled
8. Sending Warnings & Disable Logins through -k Option.
-k
Option is used to send a warning to the system and disable it for an appointed period. Please note that this option does not actually shut down or halt the system but warns the user.
$ sudo shutdown -k 5
Broadcast message from admin@dev-db (/dev/pts/2) at 20:04 ...
Warning: The system is initiating down for maintenance in 5 minutes!
So, you can see the warning is printed regardless of the actual shutdown taking place in 5 minutes.