The “shutdown” command in Linux is a powerful utility that allows users to shut down, reboot, or halt their system either immediately or at a specific time. This command is commonly used by system administrators to perform routine maintenance tasks, manage power consumption, or to shut down the system safely after performing critical operations.
The “shutdown” command accepts a variety of options that allow users to customize its behavior. For example, the “-h” option can be used to halt the system instead of shutting it down, while the “-r” option can be used to reboot the system. The “-t” option can be used to specify a time delay before the system is shut down or rebooted, allowing users to perform tasks that require a certain amount of time to complete.
Another useful option of the “shutdown” command is the “-k” option, which can be used to send a message to all logged-in users, notifying them that the system is about to be shut down. This can be helpful in situations where users may be in the middle of critical operations and need to save their work before the system is shut down.
The “shutdown” command can also be used to specify the reason for the shutdown or reboot, which can be useful for keeping track of system events and troubleshooting potential issues. The command can be used to send a message to the system logs, informing administrators and other users of the reason for the shutdown or reboot.
If you encounter the below error while running the command shutdown:
shutdown: command not found
you may try installing the below package as per your choice of distribution:
Distribution | Command |
---|---|
Debian | apt-get install sysvinit |
Ubuntu | apt-get install upstart-sysv |
Arch Linux | pacman -S systemd-sysvcompat |
Kali Linux | apt-get install runit-init |
CentOS | yum install systemd |
Fedora | dnf install systemd |
Raspbian | apt-get install upstart |
shutdown Command Examples
1. Power off (halt) immediately:
# shutdown -h now
2. Reboot immediately:
# shutdown -r now
3. Reboot in 5 minutes:
# shutdown -r +5 &
4. Shutdown at 1:00 pm (Uses 24h clock):
# shutdown -h 13:00
5. Cancel a pending shutdown/reboot operation:
# shutdown -c
Note
It is important to note that the “shutdown” command should be used with caution, especially when executing a shutdown or reboot immediately. This is because any unsaved data or running processes may be interrupted, potentially leading to data loss or other issues. It is always recommended to save all work and close all programs before executing a shutdown or reboot using the “shutdown” command.