shutdown 立即关机
sudo shutdown -h now
# 或简写为
sudo shutdown now
定时关机(例如 5 分钟后):
sudo shutdown -h +5
指定时间关机(例如 23:00):
sudo shutdown -h 23:00
取消已计划的关机:
sudo shutdown -c
选项说明:
-h(--halt):停止系统(关机)。
-r(--reboot):重启系统(非关机,但需注意区分)。
poweroff 立即关机(立即停止所有进程并断电):
sudo poweroff
halt 停止系统运行(可能需要手动断电):
sudo halt
部分系统会直接关机,具体行为取决于发行版配置。
init 切换到运行级别 0(关机):
sudo init 0
systemctl 命令(适用于 systemd 系统)
sudo systemctl poweroff
重启(非关机,但供参考):
sudo systemctl reboot
其他注意事项
权限要求:大多数关机命令需要 root 权限,需使用 sudo。
远程关机:通过 SSH 操作时,确保命令正确,避免误操作中断服务。
区别:
shutdown 更灵活(支持定时、广播通知用户)。
poweroff 直接关闭电源,halt 可能仅停止系统而不断电(依赖系统配置)。
总结
推荐使用 shutdown -h now 或 poweroff 实现立即关机,需定时操作时优先选择 shutdown 根据你的系统和需求选择合适的命令。