Shutdown Linux Server Command

See all GNU/Linux related FAQ
How do I shutdown my Linux server or computer using command line option?

The shutdown command bring the Linux based server down. In other words, the server will be powered off, and all running services will shut down safely. The data in memory will be flushed to disk too. Only the superuser (root user) can shut the system down. Let us see how to shut down a Linux server using a bash terminal.
Tutorial details
Difficulty level Easy
Root privileges Yes
Requirements Linux terminal
Category System Management
OS compatibility AlmaLinux Alpine Arch Debian Fedora Linux Mint openSUSE Pop!_OS RHEL Rocky Stream SUSE Ubuntu WSL
Est. reading time 4 minutes
Advertisement

Shutdown Linux Server Command Options

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
Sample outputs:

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
OR
# shutdown -h 20:00
The above will turn the server off at 8:00 PM.

-H option

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
Sample outputs:

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:
# poweroff

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 in five minutes time:
# shutdown -h +5 "The server is going down for 'harddisk replacement'"
Sample outputs:

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:

  1. /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.
  2. /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
Sample outputs:

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

Use the grep command or egerp command as follows to filter out data too:
# last -x shutdown | grep 'Thu Aug'

A note about systemd based Linux distros

Although the shutdown command works on systemd based modern distros, you can use the systemctl command as follows too. Therefore, you can use the following syntax too:

sudo systemctl poweroff
sudo systemctl halt
Shutdown Linux Server Command

The shutdown command may be used to halt, power-off or reboot the Linux server

Conclusion

You learned how to stately bring down Linux server for hardware replacement and other tasks. The shutdown command has many more options. Hence, read the following manual pages using the man command or help command:

man shutdown
shutdown --help

See the following commands:

🥺 Was this helpful? Please add a comment to show your appreciation or feedback.

nixCrat Tux Pixel Penguin
Hi! 🤠
I'm Vivek Gite, and I write about Linux, macOS, Unix, IT, programming, infosec, and open source. Subscribe to my RSS feed or email newsletter for updates.

1 comment… add one
  • Patrick Burwell Sep 18, 2013 @ 18:06

    Well done, very helpful… concise, but watch the spelling on your commands… :)

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre> for code samples. Your comment will appear only after approval by the site admin.