shutdown命令是拿来关掉或重启Linux系统的一个命令,它可以让系统在指定的时间或则立刻执行死机或重启的操作红旗linux官网,也可以向系统中的其他用户发送死机通知或自定义消息。shutdown命令可以让系统安全地中止所有的进程,同步所有的c盘,之后关掉或重启系统。
Linuxshutdown命令适用的Linux版本
shutdown命令在大多数Linux发行版中都是可用的,而且在一些基于systemd的系统中linux模拟,shutdown命令实际上是一个指向systemctl命令的快捷方法,以保证与SystemVinit系统的兼容性。systemd是一个新的启动系统,它在2011年开始被Fedora等一些Linux发行版采用,2015年被Debian和Ubuntu等主流发行版接受。systemd提供了一些新的命令来管理系统的死机和重启,比如:
假如你的系统是基于systemd的,你可以使用这种命令来取代shutdown命令linux安全关机命令,它们的疗效是一样的。你可以使用以下命令来检测你的系统是否使用systemd:
[linux@bashcommandnotfound.cn ~]$ ps -p 1 -o comm=
假如输出是systemd,这么你的系统就是基于systemd的。假如输出是init,这么你的系统就是基于SystemVinit的。
Linuxshutdown命令的基本句型
shutdown命令的基本句型如下:
shutdown [选项] [时间] [消息]
其中:
Linuxshutdown命令的常用选项说明
shutdown命令的常用选项有以下几个:
选项说明
-h
死机并切断电源,相当于systemctlpoweroff
-r
重启系统,相当于systemctlreboot
-H
停止系统,但不切断电源,相当于systemctlhalt
-P
死机并切断电源,与-h选项相同
-c
取消早已安排的死机或重启操作
-k
只发送消息linux安全关机命令,不执行死机或重启操作
Linuxshutdown命令的实例
以下是一些shutdown命令的实例:
[linux@bashcommandnotfound.cn ~]$ sudo shutdown -h now
[linux@bashcommandnotfound.cn ~]$ sudo shutdown -r +10 "系统将在10分钟后重启,请保存好你的工作。"
[linux@bashcommandnotfound.cn ~]$ sudo shutdown -H 23:59
[linux@bashcommandnotfound.cn ~]$ sudo shutdown -c
[linux@bashcommandnotfound.cn ~]$ sudo shutdown -k +5 "系统将在5分钟后关闭,这是一个测试消息。"
Linuxshutdown命令的注意事项
[linux@bashcommandnotfound.cn ~]$ shutdown
bash: shutdown: command not found
这时侯,你可以使用以下命令来安装shutdown命令:
[linux@bashcommandnotfound.cn ~]$ sudo apt install systemd-sysv
[linux@bashcommandnotfound.cn ~]$ sudo yum install systemd-sysv
或则,你可以使用systemctl命令来取代shutdown命令,如systemctlpoweroff或systemctlreboot等。