shutdown
shutdown
The shutdown
command in Linux is used to bring the system down in a safe and controlled manner. It ensures that all processes are terminated gracefully, filesystems are synchronized, and any remaining data in memory is written to disk before the system is powered off or rebooted.
Basic Syntax
The basic syntax of the shutdown
command is as follows:
OPTIONS: Options to control the behavior of the shutdown (e.g.,
-h
,-r
).TIME: When to perform the shutdown (e.g.,
now
,+5
).MESSAGE: An optional message that is broadcast to all logged-in users.
Common Options
-h
: Halt the system after shutdown.-r
: Reboot the system after shutdown.-P
: Power off the system (similar to-h
but ensures power off).-c
: Cancel a scheduled shutdown.-k
: Send a warning message only; do not actually shut down.
Examples
Immediate Shutdown
To shut down the system immediately:
Scheduled Shutdown
To schedule a shutdown in 10 minutes:
To schedule a shutdown at a specific time (e.g., 22:00 or 10:00 PM):
Immediate Reboot
To reboot the system immediately:
Scheduled Reboot
To schedule a reboot in 5 minutes:
Cancel a Scheduled Shutdown
To cancel a scheduled shutdown or reboot:
Send a Warning Message
To warn users about a scheduled shutdown without actually shutting down:
Using systemctl
for Shutdown and Reboot
systemctl
for Shutdown and RebootWith systems that use systemd
, you can also use the systemctl
command to perform shutdown and reboot operations. This method is often preferred on modern systems.
Shutdown
To shut down the system immediately:
Reboot
To reboot the system immediately:
Halt
To halt the system (stop all processes but do not power off):
Suspend
To suspend the system:
Hybrid Sleep
To put the system into hybrid sleep (combination of suspend and hibernate):
Handling User Sessions
The shutdown
command and systemctl
can also handle active user sessions. For instance, if users are logged into the system, a warning message can be broadcast to all logged-in users, giving them time to save their work before the system shuts down.
Custom Broadcast Messages
You can include a custom message with the shutdown command to inform users about the reason for the shutdown or any other pertinent details.
Example with Custom Message
Conclusion
The shutdown
command is a vital tool for system administrators to safely and properly bring a Linux system down. Understanding the various options and how to use them effectively ensures that shutdowns and reboots are handled gracefully, minimizing potential data loss and disruption.
help
Last updated