linux命令(shutdown)详解

shutdown命令作用

shutdown命令安全地将系统关机。 有些使用者会使用直接断掉电源的方式来关闭linux系统,这是十分危险的。因为linux与windows不同,其后台运行着许多进程,所以强制关机可能会导致进程的数据丢失﹐使系统处于不稳定的状态﹐甚至在有的系统中会损坏硬件设备。

shutdown命令格式

shutdown [OPTIONS…] [TIME] [WALL…]

命令参数

 --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

命令示例

1、立即关闭计算机

robin@robin-Lenovo:~$ shutdown -h now  #now 立刻time=0

2、在5分钟后关机,并提示关机警示信息

robin@robin-Lenovo:~$ shutdown -h +5 "system will shutdown afte 5 minutes"
Shutdown scheduled for Thu 2018-12-27 23:32:37 CST, use 'shutdown -c' to cancel.

3、在21:00关机,并提示关机警示信息

robin@robin-Lenovo:~$ shutdown -h 21:00 "system will shutdown at 21:00"
Shutdown scheduled for Fri 2018-12-28 21:00:00 CST, use 'shutdown -c' to cancel.

4、在22:00重启系统,并提示关机警示信息

robin@robin-Lenovo:~$ shutdown -r 22:00 "system will reboot at 22:00"
Shutdown scheduled for Fri 2018-12-28 22:00:00 CST, use 'shutdown -c' to cancel.