LinuxCommandLibrary

shutdown

Power down or restart the system

TLDR

Power off ([h]alt) immediately

$ shutdown -h now
copy

Reboot immediately
$ shutdown [[-r|--reboot]] now
copy

Reboot in 5 minutes
$ shutdown [[-r|--reboot]] +[5] &
copy

Shutdown at 1:00 pm (Uses 24h clock)
$ shutdown -h 13:00
copy

Cancel a pending shutdown/reboot operation
$ shutdown -c
copy

SYNOPSIS

shutdown [OPTIONS...] [TIME] [MESSAGE]

PARAMETERS

-h, --halt
    Halts the system. This stops the CPU, but leaves the power on, requiring a physical power-off or reset.

-r, --reboot
    Reboots the system, performing a full system restart.

-P, --poweroff
    Powers off the system. This is often the default behavior if neither -h nor -r is specified, completely cutting power.

-H
    Halts the system without powering it off. Similar to --halt.

-k
    Do not actually shut down, just send warning messages to all logged-in users. Useful for testing scripts or broadcasting warnings without action.

-c
    Cancels a pending shutdown. This can only be used if a time argument was specified previously to schedule a shutdown.

-t SEC
    Tells init (or systemd) to wait SEC seconds between sending warning messages and the kill signal to processes. Defaults to 5 seconds.

-f
    Skips the file system check (fsck) on the next reboot. Use with caution as it can lead to data inconsistencies if not used properly.

-F
    Forces the file system check (fsck) on the next reboot. Useful after an unclean shutdown.

TIME
    Specifies when to perform the shutdown. Can be 'now' for immediate action, '+minutes' (e.g., '+5' for 5 minutes from now), or 'hh:mm' (absolute time, e.g., '23:00').

MESSAGE
    An optional message to be broadcast to all logged-in users, informing them about the impending shutdown.

DESCRIPTION

The shutdown command is a fundamental Linux utility used to safely halt, reboot, or power off the system. It's designed to ensure data integrity by allowing all running processes to terminate gracefully before the system performs the requested action. Unlike simply cutting power, shutdown sends signals to processes, giving them time to save data and exit. It can notify all logged-in users about the impending shutdown, displaying a message and a countdown. This makes it an essential tool for system administrators to perform planned maintenance, apply updates, or safely turn off a server. It supports immediate actions or scheduling for a future time, providing flexibility for various operational needs.

While historically interacting with the init system (e.g., changing runlevels), on modern Linux distributions utilizing systemd, shutdown typically acts as a convenient front-end to systemctl commands like systemctl poweroff, systemctl reboot, or systemctl halt, maintaining a consistent interface for users regardless of the underlying init system.

CAVEATS

The shutdown command requires root privileges to execute. Users without root access or appropriate sudo permissions will not be able to run it. Be cautious with immediate shutdowns (e.g., 'shutdown now') on production systems, as they can abruptly terminate user sessions and unsaved work, potentially leading to data loss.

PERMISSIONS

Only the root user or a user granted appropriate permissions via sudo can execute the shutdown command. This security measure prevents unauthorized users from disrupting critical system operations.

GRACEFUL SHUTDOWN PROCESS

When shutdown is invoked with a time delay (e.g., '+5' or '23:00'), it first sends a warning message to all logged-in users, allowing them time to save their work and log out. As the time approaches, it sends increasingly urgent warnings. Finally, it sends a SIGTERM signal to all processes, followed by SIGKILL for stubborn processes, ensuring a clean termination of services and applications before the system halts or reboots.

HISTORY

The shutdown command has been a staple in Unix-like operating systems since their early days, primarily used for changing system runlevels to safely halt or reboot. Its core functionality of facilitating a graceful system termination has remained consistent. In modern Linux distributions, particularly those that have adopted systemd as their init system, shutdown often acts as a compatibility wrapper, internally invoking the equivalent systemctl commands (e.g., systemctl poweroff). This evolution reflects the shift in underlying system management without compromising the familiar user interface and functionality for administrators.

SEE ALSO

halt(8), reboot(8), poweroff(8), systemctl(1), init(8)

Copied to clipboard