In this article we have covered Linux commands that enable a user or system administrator to shutdown or reboot computer systems via the command line interface. We have also discussed how such operations can be scheduled i.e for system upgrades or maintenance.
Table of contents.
- shutdown command.
- reboot, halt, poweroff commands.
Shutting down or rebooting systems can be done using pressing Ctrl+Alt+Del then choosing an appropriate action however the graphical user interface consumes alot of system resources as compared to the command line interface, furthermore scheduling such operations is easier using the terminal.
Here we cover four commands that perform the same actions however we will find that others are well suited to a certain task than others.
One should understand the terms shutdown, reboot, halt, hibernate, sleep, logout as a prerequisite.
This command is used to shutdown a device safely.
The syntax is as follows,
shutdown [OPTIONS...] [TIME] [MESSAGE...]
Commonly used options include,
- -P, --poweroff, to poweroff the machine.
- -r, --reboot, to reboot the machine.
- -H, --halt, to halt the machine.
- -c, to cancel a pending shutdown.
TIME specifies a time argument to schedule a reboot, or schedule a reboot after a certain period of time, or specify an exact time for an immediate shutdown.
The time format is as follows;
- hh:mm, to schedule a specific time.
- +m, to specify the number of minutes until shutdown.
MESSAGE argument is used to specify a message or instructions which will notify users.
To shutdown a system at 14:30 pm server/system time, we write,
We can cancel this or any reboot or shutdown by writing,
We can also cancel a shutdown with a message as follows,
shutdown -c "Cancelling shutdown"
To schedule a shutdown in the next 20 minutes, we write,
To shutdown a system immediately we write,
or we can also write,
To add a message we write,
shutdown +20 "Shutdown in 20 minutes for updates"
To reboot a machine we use the -r option with shutdown as follows,
shutdown -r +20
The command will reboot the machine in the next 20 minutes.
We can also schedule a reboot and add a message as follows,
shutdown -r 13:00 "Rebooting system at 13:00"
reboot, halt, poweroff commands.
The reboot command is used to reboot a system.
The syntax is as follows,
To poweroff using reboot we write,
We can also force a reboot by using the -f option,
The halt command halts a system,
The poweroff command powers off the system,
We have covered the shutdown command and various examples e.g shutting a computer down immediately, scheduling a shutdown, displaying shutdown messages and canceling a shutdown.
Alternatively one can press Ctrl+Alt+Del to shutdown, reboot or halt the system.
Assuming we scheduled a shutdown, five minutes before the system goes down, no new logins will be permitted, this is possible because of the /etc/nologin file which is created.
- Execute the command shutdown --help or man shutdown for its manual pages.