Pulling the plug can lose data that has not yet been written to disk. A clean shutdown tells services to stop, flushes data and unmounts filesystems. The commands below normally need administrator rights, although desktop users logged in locally are often allowed some of them.
Shutdown with timing
shutdown accepts a time and an optional message for logged in users:
$ sudo shutdown -h now
$ sudo shutdown -r +10 "Rebooting for updates"
$ sudo shutdown -h 23:00-h stops the machine, which on a systemd system means powering off by default. -r reboots. +10 means in ten minutes. If you give no time to the systemd version, it waits one minute.
To cancel a pending shutdown:
$ sudo shutdown -cShort commands
poweroff, reboot and halt also exist. Halting stops the operating system but may leave the hardware powered on. On systemd systems you can use:
$ sudo systemctl poweroff
$ sudo systemctl rebootOn System V systems, init 0 halts or powers off and init 6 reboots.
Sleeping instead of stopping
$ systemctl suspend
$ systemctl hibernateSuspend keeps your session in RAM and puts the machine into a low power state. It resumes quickly, but a machine that loses all power loses the session.
Hibernate saves the memory contents to disk, usually swap space, and powers off. It resumes more slowly and survives power loss. It needs enough swap and correct resume setup, and some distributions do not enable it by default.
systemctl hybrid-sleep does both: it writes the image to disk and then suspends.
Support depends on hardware and firmware. You can see which sleep states the kernel offers:
$ cat /sys/power/state
freeze mem diskYour list may be different.
Before you act on a server
Check who is logged in with who, and make sure you have the right machine: hostname takes a second. A remote machine that is powered off may need someone to press the button.
Try it
On a virtual machine, schedule a shutdown with sudo shutdown -h +5 "test", then cancel it with sudo shutdown -c. Then run cat /sys/power/state and see which states are listed.
Check your understanding
Power States
All 5 sections ยท no timer
Unlimited retries
Questions from every section are combined into one assessment. Answer them all correctly to complete the article.
Your completion saves in this browser. Sign in to sync it to your account.