“shutdown” Command Examples in Linux

Introduction

In this article, we are going to learn Linux shutdown command with examples. The shutdown command is used to halt/shutdown, reboot the Linux Operating System.

When shutdown is entered correctly—as root, and with a valid time argument — it does the following.

  • Notifies all users the system is going down
  • Blocks additional logins
  • Notifies all running programs so they can close/save files and exit gracefully
  • Notifies init to change the runlevel
  • Psssst! Tell init to take us to level X

Shutdown the system Immediately

To Shutdown a Linux operating system use shutdown command with argument -h. Here I am using the word “now” to Shutdown the System immediately.

Syntax :

# shutdown [Option] [Time]
# shutdown -h now          ### Immediate Shutdown a Linux System 

Shutdown the System After Some Time

You can set time in minutes after which system will get Shutdown. For Example, if you want to Shutdown the system after 1 Minute then set the time as +1 with the shutdown command. Refer the command below.

# shutdown -h +1           ### Shutdown the System after 1 Minute

Broadcast message from root@localhost.localdomain
 (/dev/pts/1) at 20:19 ...

The system is going down for halt in 1 minute!

Broadcasting Message Before Shutting Down the System

If you want to send some message to the users before shutdown the system then you can do so by using Linux shutdown command. Refer the command below. The message is Highlighted in Red Color.

# shutdown -h +10 "System is going to Shutdown"  # Send a Message to user before Shutdown the System

Broadcast message from root@thegeekdiary.com
 (/dev/pts/0) at 8:43 ...

The system is going down for halt in 10 minutes!
System is going to Shutdown

The “halt” Command

There are other commands available by which you can Shutdown the system. For Example halt command can be used to shutdown the system.

# halt        ### Shutdown a Linux System

The “poweroff” Command

Also you can use poweroff command to shutdown the system.

# poweroff           ### Shutdown the System
# poweroff -f        ### Shutdown the System Forcefully

Restarting the System

To restart a Linux system use shutdown command with argument -r. Here I am using the word “now” to Restart the system Immediately.

# shutdown -r now         ### Restart a System Immediately

You can set time in minutes after which system will get Restart. Here I want to restart the system after 2 Minutes so set time as +2 with Linux shutdown command.

# shutdown -r +2         ### Restart the system after 2 Minutes

Broadcast message from root@localhost.localdomain
 (/dev/pts/1) at 20:21 ...

The system is going down for reboot in 2 minutes!

The “reboot” Command

You can also use reboot command to Restart the Linux Operating System.

# reboot            ### Restart the System

# reboot -f           ### Restart the System Forcefully

Broadcasting Message Before Rebooting a System

If you want to send some message to the users before Reboot the system then you can do so by using Linux shutdown command. Refer the command below.

# shutdown -r +10 "System is going to Reboot"

Broadcast message from root@thegeekdiary.com
 (/dev/pts/0) at 8:45 ...

The system is going down for reboot in 10 minutes!
System is going to Reboot

Cancelling a shutdown Command

shutdown command with argument -c can be used to cancel a running shutdown.

# shutdown -c         ### Cancel a Running Shutdown

Sending a Fake Shutdown Warning Message

shutdown command with argument -k will only send a fake shutdown warning to user but will not shutdown.

# shutdown -k +1 "System is going to Shutdown"        ### Send a fake Shutdown Warning
 
Broadcast message from root@thegeekdiary.com
 (/dev/pts/0) at 9:07 ...

The system is going down for maintenance in 1 minute!
System is going to Shutdown

Poweroff a System

To Power Off the Linux system just use shutdown command with argument -P. Here I am going to Power Off the system after 1 Minute.

# shutdown -P +1        ### Power Off the System after 1 Minute

Broadcast message from root@thegeekdiary.com
 (/dev/pts/0) at 9:10 ...

The system is going down for power off in 1 minute!

Difference Between “halt” & “poweroff” Commands

Here you might be thinking that that is the difference between Halt and Power Off. The exact difference between Halt and Power Off is in Halt only the Operating System gets down but in case of Power Off the Operating System get down and then system instruct the ACPI to send a signal to Power Unit to Power Off the System. ACPI stands for Advance Configuration Power Interface.

For more help on Linux shutdown, you can use the below command.

# shutdown --help   # For more Help on Shutdown Command
Usage: shutdown [OPTION]... TIME [MESSAGE]
Bring the system down.

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

I hope you have found the article useful. shutdown, reboot, poweroff are very dangerous commands and has to be used very cautiously on a production system. As a thumb rule it is always adviced to confirm the hostname or IP address of the system you are going to reboot or shutdown.

Related Post