The shutdown command is the preferred method of rebooting or shutting down Linux. Using shutdown you can schedule a reboot or shutdown at some time in the future, and shutdown will automatically notify all logged-in users of the impending action. As the time approaches, it will alert logged-in users with a greater frequency and urgency.
With shutdown, a message can be specified that is sent to all logged-in users along with each alert. The basic syntax of the shutdown command is:
# shutdown time [warning-message]
|-k||Don’t really shutdown; only send the warning messages to everybody.|
|-r||Reboot after shutdown.|
|-h||Halt after shutdown.|
|-c||Cancel an already running shutdown. With this option, it is of course not possible to give the time argument, but you can enter an explanatory message on the command line that will be sent to all users.|
|time||When to shutdown, most often now (This is a required argument).|
|warning-message||Message to send to all users. Surround with quotes if messages contain spaces.|
The reboot, poweroff, and halt Commands
When not in runlevel 0 or 6, the reboot and halt commands, unlike older versions of Unix, call the shutdown command with the -r or -h option, respectively. The poweroff command switches to runlevel 0 and removes power if supported by the hardware.
A full list of runlevels looks like this:
- 0 Halt: This is the runlevel at which the system shuts down and is unsuitable for any type of application or service.
- 1 Single-User mode: This runlevel does not start any networking or multiuser services, but it does boot the system into single-user mode under which only the root user can log in. This runlevel is ideal for system administrators who wish to perform system maintenance or repair activities.
- 2 Multi-user mode, console logins only (without networking): This runlevel does not start the network but it does boot the system into a multiuser environment with text-based console login capability.
- 3 Multi-User mode, console logins only: This runlevel gives all the features of runlevel 2, but it provides full networking services. This is the most common runlevel for server-based systems that do not require or use a graphical desktop environment.
- 4 Not used/User-definable: This runlevel is undefined and can be configured to provide a custom environment.
- 5 Multi-User mode, with display manager as well as console logins (X11): This runlevel is similar to runlevel 3, but is generally associated for systems with desktop environments.
- 6 Reboot: This runlevel reboots the system and is unsuitable for any type of application or service.