Linux "shutdown" Command Examples

The shutdown Command

“shutdown” is a system administration command which terminates all processing. when maybe a specific time (in hh:mm format), a number of minutes to wait (in +m format), or now. A broadcast message notifies all users to log off the system. Processes are signaled with SIGTERM to allow them to exit gracefully. /etc/init is called to perform the actual shutdown, which consists of placing the system in runlevel 1. Only privileged users can execute the shutdown command.

Options

  • -a - When called from init, shut down only if one of the users listed in the file /etc/shutdown.allow is currently logged in.
  • -c - Cancel a shutdown that is in progress.
  • -f - Reboot fast, by suppressing the normal call to fsck when rebooting.
  • -F - Force a filesystem check (fsck) on reboot.
  • -h - Halt or power off the system when shutdown is complete. Which it does depends on system hardware/BIOS.
  • -H - Halt the system when shutdown is complete.
  • -k - Print the warning message, but suppress actual shutdown.
  • -P - Power off the system when shutdown is complete.
  • -r - Reboot the system when shutdown is complete.

Examples of shutdown command

1. To shutdown a system:

 # shutdown

2. To reboot a system:

# shutdown -r

3. To halt a system:

 # shutdown -h

4. To halt the system after bringing down:

# shutdown -H

5. To poweroff the system:

# shutdown -P

6. To cancel a running shutdown:

# shutdown -c

7. To only send out the warning messages:

# shutdown -k

8. Shutdown a system with 10 minutes delay and with a broadcast message “scheduled maintenance”:

# shutdown -h +10 "scheduled maintenance"

The time may be a number of minutes preceded by a plus sign, like +10; an absolute time in hours and minutes, like 16:25; or the word now to mean immediately.

Changing Runlevels

The init program is called at boot time and among other things it controls the state—or the runlevel of the machine. The various runlevels dictate what programs are allowed to be run. The important runlevels are:

  • 0 - Halt the machine
  • 1 - Single-user (maintenance) mode
  • 5 - Normal operating mode
  • 6 - Reboot

We’re starting from runlevel 5, so we’ll never need to use shutdown to get us there. But we can use the following command-line arguments with shutdown to allow us to either reboot or halt the machine at shutdown:


-h Halt the machine (runlevel 0)
-r Reboot the machine (runlevel 6)