这是我参与11月更文挑战的第10天,活动详情查看:2021最后一次更文挑战
Linux 小知识 丨关机和重启命令
关机命令
shutdown [-t seconds] [-rkhncfF] time [message] # 关机
[root@VM-8-10-centos ~]# shutdown --help
shutdown [OPTIONS...] [TIME] [WALL...]
Shut down the system.
--help Show this help
-P --poweroff Power-off the machine
-r --reboot # 关机后重新开机
-h # 关机后停机
-k # 并不会真的关机,知识将警告讯息传送给所有使用者。
--no-wall Don't send wall message before halt/power-off/reboot
-c # 取消目前已经进行中的关机动作
-F # 关机时强制进行fsck动作
-f # g关机时不做fcsk动作(检查Linux档系统)
-n # 不采用正常程序来关机,用强迫的方式杀掉所有执行中的程序后自行关机
-t seconds # 设定在几秒钟之后进行关机程序
time # 设定关机的时间
[root@VM-8-10-centos ~]# shutdown
Shutdown scheduled for Thu 2021-11-04 14:34:13 CST, use 'shutdown -c' to cancel.
[root@VM-8-10-centos ~]# shutdown -c
[root@VM-8-10-centos ~]# shutdown +1 "一分钟之后关机" #延迟一分钟后关机, 并给出警告信息
[root@VM-8-10-centos ~]# shutdown -r +1 "准备重启了" # 关机后重启
[root@VM-8-10-centos ~]# shutdown -h now # 立马关机
showdown 命令示例
# shutdown
# shutdown now
# shutdown 13:20
# shutdown -p now ### 关闭机器
# shutdown -H now ### 停止机器
# shutdown -r09:35 ### 在 09:35am 重启机器
shutdown命令实现定时自动关机
$ shutdown -r now 关机后重启
$ shutdown -h now 关机后不重启
$ shutdown -r +10 10分钟后重启
$ shutdown -r 10:00 10点钟重启
$ shutdown -h +10 10分钟后关机
$ shutdown -h 10:00 10点钟关机
重启命令
reboot [-n][-w][-d][-f][-i]
# -n 在重开机前不做将记忆体资料写会硬盘的动作
# -w 并不会真的重开机,只是把记录写到 /var/log/wtmp档案里
# -d 不会记录写到 /var/log/wtmp档案里 (-n 包含了-d)
# -f 强迫重开机,不呼叫shutdown这个指令
# -i 在重开机之前先把所有网络相关的装置先停止
[root@VM-8-10-centos ~]# reboot --help
reboot [OPTIONS...] [ARG]
Reboot the system.
--help Show this help
--halt Halt the machine
-p --poweroff Switch off the machine
--reboot Reboot the machine
-f --force Force immediate halt/power-off/reboot
-w --wtmp-only Don't halt/power-off/reboot, just write wtmp record
-d --no-wtmp Don't write wtmp record
--no-wall Don't send wall message before halt/power-off/reboot