The shutdown command bring the Linux based system or server down. Only the superuser (root user) can shut the system down. Open a command-line terminal (select Applications > Accessories > Terminal), or login to remote server using the ssh command, and then type the following command to shutdown the Linux server immediately:
# shutdown -h now
The shutdown command arranges for the system to be brought down in a safe way i.e. it will remove power from a servers's main components in a controlled way. All logged-in users are notified that the system is going down and, within the last five minutes of TIME, new logins are prevented. 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 format. In this example, shutdown the system in 5 minutes:
# shutdown -h +5
Broadcast message from vivek@vivek-laptop (/dev/pts/0) at 16:57 ... The system is going down for halt in 5 minutes!
-h (halt) option
The -h option 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:
# shutdown -h 6:30
# shutdown -h 20:00
The above will turn the server off at 8:00 PM.
The -H option requests that the system be halted after it has been brought down:
# shutdown -H +10
-P (power off) option
The -P option requests that the system be powered off after it has been brought down:
# shutdown -P +10
Broadcast message from vivek@vivek-laptop (/dev/pts/1) at 17:00 ... The system is going down for power off in 10 minutes!
You can also type the poweroff command instead of typing shutdown -P:
How do I Cancel The System Shutdown?
You can press [CTRL+C] or type the following command to cancel a running shutdown:
# shutdown -c
Sample output (the command was issued on tty01):
shutdown -h +10 Broadcast message from vivek@vivek-laptop (/dev/pts/1) at 17:04 ... The system is going down for halt in 10 minutes! shutdown: Shutdown cancelled
How Do I Display Custom Shutdown Message?
Use the following syntax:
# shudown -h TIME "YOUR-MESSAGE-HERE"
In this example, shutdown the server for hard disk replacement:
# shutdown -h +5 "The server is going down for 'harddisk replacement'"
Broadcast message from vivek@vivek-laptop (/dev/pts/0) at 17:11 ... The system is going down for halt in 5 minutes! The server is going down for 'harddisk replacement'
Linux Server Shutdown and Log Files
The following two files are updates when the system goes down for the poweroff / halt or reboot operations:
- /var/run/utmp - Where the current runlevel will be read from; this file will also be updated with the runlevel record being replaced by a shutdown time record.
- /var/log/wtmp - A new runlevel record for the shutdown time will be appended to this file.
How Do I Display the System Shutdown Time?
Use the last command as follows:
# last -x shutdown
shutdown system down 2.6.18-238.el5 Sat Jan 22 06:40 - 05:51 (10+23:10) shutdown system down 2.6.18-194.32.1. Sun Jan 16 13:26 - 06:40 (5+17:14) shutdown system down 2.6.18-194.26.1. Sat Jan 8 04:17 - 13:25 (8+09:08) shutdown system down 2.6.18-194.26.1. Mon Nov 15 16:46 - 04:16 (53+11:30) shutdown system down 2.6.18-194.17.1. Wed Oct 27 01:00 - 02:00 (18+02:00) shutdown system down 2.6.18-194.8.1.e Thu Aug 12 00:18 - 09:02 (20+08:43) shutdown system down 2.6.18-194.8.1.e Wed Jul 14 14:07 - 16:19 (5+02:12) shutdown system down 2.6.18-194.8.1.e Tue Jul 13 20:21 - 14:06 (17:45) shutdown system down 2.6.18-194.8.1.e Tue Jul 13 12:13 - 20:20 (08:07) shutdown system down 2.6.18-194.8.1.e Tue Jul 13 11:48 - 12:13 (00:24) shutdown system down 2.6.18-194.8.1.e Tue Jul 13 10:38 - 11:48 (01:09) shutdown system down 2.6.18-194.el5 Tue Jul 13 10:32 - 10:38 (00:05) wtmp begins Tue Jul 13 10:26:19 2010
- Man pages: shutdown(8)