We will see various types of commands for shutdown and reboot for Linux in this article.
Shutdown Syntax:
shutdown [OPTION]… TIME [MESSAGE]
Options:
-r reboot after shutdown
-h halt or power off after shutdown
-H halt after shutdown (implies -h)
-P power off after shutdown (implies -h)
-c cancel a running shutdown
-k only send warnings, don’t shutdown
-q, –quiet reduce output to errors only
-v, –verbose increase output to include informational messages
–help display this help and exit
–version output version information and exit
TIME may have different formats, the most common is simply the word ‘now’ which
will bring the system down immediately. Other valid formats are +m, where m is
the number of minutes to wait until shutting down and hh:mm which specifies the
time on the 24hr clock.
Logged in users are warned by a message sent to their terminal, you may include
an optional MESSAGE included with this. Messages can be sent without actually
bringing the system down by using the -k option.
If TIME is given, the command will remain in the foreground until the shutdown
occurs. It can be cancelled by Control-C, or by another user using the -c
option.
The system is brought down into maintenance (single-user) mode by default, you
can change this with either the -r or -h option which specify a reboot or
system halt respectively. The -h option can be further modified with -H or -P
to specify whether to halt the system, or to power it off afterwards. The
default is left up to the shutdown scripts.
A simple way to shutdown the server (the “1” indicates time in minutes):
[root@localhost ~]# shutdown 1
Broadcast message from root@localhost.localdomain
(/dev/pts/0) at 20:13 …
The system is going down for maintenance in 1 minute!
To have the server reboot after a shutdown:
[root@localhost ~]# shutdown -r 1
Broadcast message from root@localhost.localdomain
(/dev/pts/0) at 20:15 …
The system is going down for reboot in 1 minute!
You can have a custom message with the shutdown command:
[root@localhost ~]# shutdown 1 “System will poweroff for hardware change”
Broadcast message from root@localhost.localdomain
(/dev/pts/0) at 20:19 …
The system is going down for maintenance in 1 minute!
System will poweroff for hardware change
Due to any reason you need cancel the shutdown:
Hold Crtl and press C
Or
On another terminal enter the following command
Shutdown –c (need root privileges)
To Reboot your system
To simply reboot your server:
reboot