What it does
On RHEL these commands are part of systemd. They ask systemd to stop all services in the right order, write all data to disk and then reboot or power off.
shutdowncan wait (a number of minutes or a clock time), sends a warning to logged-in users, and can be cancelled.reboot,poweroffandhaltact at once. They are the same assystemctl reboot,systemctl poweroffandsystemctl halt.
halt stops the system but does not switch off the power; use poweroff to switch off.
How to write it
shutdown [OPTIONS] [TIME] [MESSAGE]
shutdown -c
reboot [OPTIONS]
poweroff [OPTIONS]
halt [OPTIONS]Options 19
Most used
shutdown
reboot, poweroff, halt
Nothing matches this filter.
Examples 11
$ run as a normal user# run as root (or with sudo)
1Reboot now
rebootThe same as
systemctl reboot.2Power off now
poweroffThe same as
systemctl powerofforshutdown -h now.3Reboot in 10 minutes with a message
shutdown -r +10 "Kernel update. Please save your work."Logged-in users see the message now and again before the reboot.
4Power off at a clock time
shutdown -h 23:30 "Hardware maintenance tonight"24-hour time of the server's time zone.
5Cancel a planned shutdown
shutdown -cUsers get a message that it was cancelled.
6Show the planned shutdown
shutdown --showCheck before you plan another one.
7Only warn users, do not shut down
shutdown -k +5 "Test message: maintenance starts soon"Useful to test what users see.
8Reboot a remote server and wait until it is back
ssh root@server2 reboot; sleep 60; until ssh -o ConnectTimeout=5 root@server2 true; do sleep 10; done; echo "server2 is back"A simple loop in a patch script.
9Reboot after an update only when the kernel changed
needs-restarting -rreturns 1 when a reboot is needed.10Force a reboot when services hang
systemctl reboot --forceSkips the clean stop of services. Use only when a normal reboot hangs.
11See past reboots
last -x reboot shutdown | headWhen did the system reboot, and who shut it down?
Nothing matches this filter.
Watch out
haltdoes not power off. On real hardware the machine stays on with the screen showing "System halted".reboot -ffis like pulling the plug: open files can be damaged.- On a remote server, a
poweroffcannot be undone without someone at the machine (or a remote console).
Files
/var/log/wtmp- Records of reboots and logins (read with
last). /run/nologin- Made by shutdown 5 minutes before the time: new logins are refused.
Tips to remember
- Now:
reboot/poweroff. Later:shutdown -r +10. Undo:shutdown -c.