How to Use Linux Shutdown and Reboot Command with Examples

by Himanshu Arora on February 11, 2014

This tutorial explains various command line options available for the Linux shutdown and reboot commands.

Linux shutdown command options

Syntax:

shutdown [OPTION]… TIME [MESSAGE]

From the syntax we see that besides OPTIONS and TIME, there is a MESSAGE that can be produced on the command line through this command. Please note that you need to have root privileges to execute this command.

1. A basic example

In its very basic form, the shutdown command can be used as :

$ sudo shutdown 5
[sudo] password for admin: 

Broadcast message from admin@dev-db
	(/dev/pts/2) at 19:44 ...

The system is going down for maintenance in 5 minutes!

So we see that shutdown command initiated the process of system shutdown.

2. Initiate the reboot process through -r option

The option -r can be used to to initiate system reboot through the shutdown command.

Here is an example :

$ sudo shutdown -r 5

Broadcast message from admin@dev-db
	(/dev/pts/2) at 19:49 ...

The system is going down for reboot in 5 minutes!

So we see that system reboot was initaited.

3. Poweroff or halt off the system using -h option

This option lets the system decide to either power off or halt the system once it’s brought down.

Here is an example :

$ sudo shutdown -h 5

Broadcast message from admin@dev-db
	(/dev/pts/2) at 19:51 ...

The system is going down for halt in 5 minutes!

So we see that system decided to halt when -h option was passed to shutdown command on my machine.

4. Insist the system to Power off using -P option

The -P option lets the user to insist system to power off once it’s brought down.

Here is an example :

$ sudo shutdown -P 5

Broadcast message from admin@dev-db
	(/dev/pts/2) at 19:53 ...

The system is going down for power off in 5 minutes!

So we see that system prepared to power off.

5. Print a message using shutdown command

User can also print a custom message through shutdown command. This could be helpful when the the user or admin wants to convey to all the currently logged in users the reason of shutdown.

Here is an example :

$ 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 going down for maintenance in 5 minutes!
System is shutting down to install new updates

So we see that the message was displayed as the last line in the output above.

6. Insist the system to be halted using -H option

Shutdown command provides an option -H through which the user/admin can insist the system to be halted once brought down.

Here is an example :

$ sudo shutdown -H 5

Broadcast message from admin@dev-db
	(/dev/pts/2) at 19:58 ...

The system is going down for halt in 5 minutes!

7. Cancel the shutdown operation using -c option

If due to any reason the shutdown needs to be cancelled within the time mentioned in the shutdown command, the -c option can be used to cancel the shutdown.

Here is an example :

$ sudo shutdown -c

Running the above command in a separate shell window affects an ongoing shutdown in the following way :

$ sudo shutdown 5

Broadcast message from admin@dev-db
	(/dev/pts/2) at 19:59 ...

The system is going down for maintenance in 5 minutes!
shutdown: Shutdown cancelled

So we see that shutdown was canceled.

8. Send out warnings and disable logins using -k option

The -k option provided by the shutdown command does not actually halts or power off’s the system but just sends the warnings and disables the logins.

Here is an example :

$ sudo shutdown -k 5

Broadcast message from admin@dev-db
	(/dev/pts/2) at 20:04 ...

The system is going down for maintenance in 5 minutes!

So we see that just a warning is produced but no shutdown took place after 5 minutes.

Linux reboot command options

The reboot command allows the system administrator to reboot a system. This command is kind of a front end to shutdown command only except when it is run with –force option or when the runlevel is 0 or 6. In these two cases, this command invokes the reboot() system call to perform the desired operation.

Syntax for reboot command:

reboot [OPTION]...

So we see that unlike shutdown command discussed above, reboot command neither accepts any time argument nor any message argument. It simply reboots your system the moment it is run.

1. Reboot your system

This can be done by simply running the reboot command with root privileges.

Here is the example :

$ reboot

2. Initiate forced reboot using -f option

This option invokes the reboot() system call leading to non-graceful reboot of the system.

Here is an example :

$ reboot -f

3. The /var/run/wtmp and /var/run/utmp files

While dealing with reboot command, one must have the knowledge of these files :

/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.

A dummy update to /var/log/wtmp can be done using -w option.

$ sudo reboot -w
[sudo] password for admin:

4. Check the update status of /var/log/wtmp

As /var/log/wtmp is not a readable file so it’s update status could be checked using the cksum command. This command should show an updated checksum when reboot -w is run.

Here is an example. From the following output, we can see that the checksum for the file changed, after we did the reboot -w.

$ cksum /var/log/wtmp
5957036 402048 /var/log/wtmp

$ sudo reboot -w

$ cksum /var/log/wtmp
978698526 402432 /var/log/wtmp

Linux Sysadmin Course Linux provides several powerful administrative tools and utilities which will help you to manage your systems effectively. If you don’t know what these tools are and how to use them, you could be spending lot of time trying to perform even the basic administrative tasks. The focus of this course is to help you understand system administration tools, which will help you to become an effective Linux system administrator.
Get the Linux Sysadmin Course Now!

If you enjoyed this article, you might also like..

  1. 50 Linux Sysadmin Tutorials
  2. 50 Most Frequently Used Linux Commands (With Examples)
  3. Top 25 Best Linux Performance Monitoring and Debugging Tools
  4. Mommy, I found it! – 15 Practical Linux Find Command Examples
  5. Linux 101 Hacks 2nd Edition eBook Linux 101 Hacks Book

Bash 101 Hacks Book Sed and Awk 101 Hacks Book Nagios Core 3 Book Vim 101 Hacks Book

{ 12 comments… read them below or add one }

1 Jalal Hajigholamali February 11, 2014 at 11:52 pm

Hi,
Thanks for very useful article…
thanks again

2 Maroman February 12, 2014 at 12:05 am

just small remark.

in Debian shutdown command with -H and -P flags can only be used along with -h flag. so it should be shutdown -hH now etc.

cheers,

3 Renate Morgenstern February 12, 2014 at 2:58 am

Thanks for information. I also would like to reboot the system and afterwards to a fsck on the filesystem. I tried shutdown -rF but it did not work.
How could I do this?
Thanks
Renate

4 Philippe Petrinko February 12, 2014 at 4:07 am

typo here :
So we see that system reboot was initaited.
=>
initiated

5 sacarde February 12, 2014 at 6:48 am

hi,
but this parameters work even if I use systemd ?

6 Ed February 12, 2014 at 7:13 am

Excellent

7 Rick February 12, 2014 at 9:48 am

Now off to research the differences between Shutdown, Halt and Power off. Perhaps they really mean the same for a desktop system.

8 JC February 12, 2014 at 9:59 am

#8 -k … just sends the warnings and disables the warnings.
Second warnings should be logins.

9 Selvakumar February 12, 2014 at 10:37 am

Please correct the sentence:

but just sends the warnings and disables the warnings.

I think its supposed to disable the logins, not the warnings. :)

10 Ramesh Natarajan February 12, 2014 at 11:09 pm

@Phillippe, JC, Selvakumar,

Thanks for pointing out the typo. It is fixed now.

11 RJ February 13, 2014 at 8:47 am

Hi,
would be possible to make a timed poweroff in systemd?
For example, how to do something similar to
# shutdown -h +5

Is there any option in systemd or do I need to write a script for it?

Thanks,
RJ

12 Philemon Mindra February 18, 2014 at 1:48 am

i had not explored many options with the shutdown and reboot commands but these were really helpful.
Many thanks for the posts

Leave a Comment

Previous post:

Next post: