shutdown命令
可以在终端输入shutdown --help
或者man shutdown
来查看:
@ubuntu:~$ shutdown --help
shutdown [OPTIONS...] [TIME] [WALL...]
Shut down the system.
--help Show this help
-H --halt Halt the machine
-P --poweroff Power-off the machine
-r --reboot Reboot the machine
-h Equivalent to --poweroff, overridden by --halt
-k Don't halt/power-off/reboot, just send warnings
--no-wall Don't send wall message before halt/power-off/reboot
-c Cancel a pending shutdown
@ubuntu:~$
或者man shutdown
可以查看更加详细的操作说明。
除以上这些参数外,还有一些,共总结如下
-H: (halt)表示关闭设备
-P: 关机
-h: 等同于-P
-k: 仅发送警告消息给登录用户,不真正关机(仅仅root用户可用)
-c: 取消关机
-t mins: 过几分钟关机,默认1分钟。
-f:关机再次开机后,略过fsck磁盘检查
-F:关机再次开机后,强制进行fsck磁盘检查
halt和shutdown区别
- 1.halt可以在不理会目前系统状况下,进行硬件关机的特殊功能;
- 2.shutdown根据目前的启动的服务,在逐次关闭各个服务后才进行关机;
- 3.halt会先调用shutdown,而shutdown最后会调用halt。
如:
# 得到当前时间
@ubuntu:~$ date
Tue Jun 12 16:14:15 PDT 2018
# 十分钟后关机
@ubuntu:~$ shutdown -t 10
Shutdown scheduled for Tue 2018-06-12 16:24:18 PDT, use 'shutdown -c' to cancel.
# 十分钟后关机
@ubuntu:~$ shutdown -h 10
Shutdown scheduled for Tue 2018-06-12 16:24:31 PDT, use 'shutdown -c' to cancel.
# 在20:00关机
@ubuntu:~$ shutdown -t 20:00
Shutdown scheduled for Tue 2018-06-12 20:00:00 PDT, use 'shutdown -c' to cancel.
# 在20:00关机
@ubuntu:~$ shutdown -h 20:00
Shutdown scheduled for Tue 2018-06-12 20:00:00 PDT, use 'shutdown -c' to cancel.
# 不执行关机,仅发送警告消息,必须root用户
@ubuntu:~$ shutdown -k now "system will power off"
Must be root.
遗留问题
在执行shutdown -H
时,出现以下错误:
@ubuntu:~$ shutdown -H
Failed to call ScheduleShutdown in logind, proceeding with immediate shutdown: Action org.freedesktop.login1.halt is not registered
@ubuntu:~$
reboot、poweroff、halt命令
这三个命令使用方式完全一样,可以通过man reboot
或者reboot --help
可查看具体的说明。
如:
$ reboot 重启
$ reboot -p 重启
$ poweroff --reboot 重启
$ poweroff 关机
$ halt -p 关机