linux常用命令:shutdown 命令

本文详细介绍了Linux系统中shutdown命令的使用方法,包括其基本格式、功能原理、各种选项参数及多个实用示例。此外还提供了其他关机命令如init 0、init 6和reboot等的使用介绍。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 shutdown以一种安全的方式关闭系统。

1.命令格式:

  shutdown [参数] [时间] 

2.命令功能:

    功能:  系统关机命令,shutdown指令可以关闭所有程序,并依用户的需要,进行重新开机或关机的动作,所有登陆用户都可以看到关机信息提示。

    原理:  shutdown通过通知init进程,要求它改换运行级别来实现。运行级别0用来关闭系统,运行级别6用来重启系统,运行级别1用来使系统进入执行系统管理任务状态,如果没有给出 -h 或 -r 标志时,这是 shutdown 命令的默认工作状态。

3.选项参数:

1) -h  将系统关机

2) -r  shutdown之后重新启动

3) -k  只是送出信息给所有用户,但不会实际关机

4) -f  重启时跳过磁盘检测

5) -F  重启时强制磁盘检测。

6) -c  取消运行中的 shutdown 进程。不可能为此选项指定 time 参数,但你可以在命令行输入一条解释消息来向所有用户说明。

     (一般的shutdown指令可以用按“+”号来进行中断) 

 

4.使用实例:

  1)在特定的时间执行关机命令:

shutdown -h now         //立即关机
shutdown -h 12:00      //在12:00关机

  2)指定5分钟后关机,同时送出警告信息给登入用户

root@Unbuntu:/home/sunjimeng# shutdown +5 "This System will be shutdown in 5 minute!"

来自sunjimeng@Unbuntu的广播信息
    (/dev/pts/6) 于 10:38 ...

The system is going down for maintenance in 5 minutes!   //系统提醒
This System will be shutdown in 5 minute!          //用户自定义提醒

      3)取消关机命令

shutdown -c

      4)在特定时间执行关机重启命令,并取消

[xiong@localhost ~]$ su root            //必须是root用户
密码:
[root@localhost xiong]# shutdown -r +3 "3分钟后关机重启"
Shutdown scheduled for 三 2016-06-29 19:47:26 PDT, use 'shutdown -c' to cancel.
[root@localhost xiong]# 
Broadcast message from root@localhost.localdomain (Wed 2016-06-29 19:44:26 PDT):

3分钟后关机重启
The system is going down for reboot at Wed 2016-06-29 19:47:26 PDT!
[root@localhost xiong]# shutdown -c

Broadcast message from root@localhost.localdomain (Wed 2016-06-29 19:44:50 PDT):

The system shutdown has been cancelled at Wed 2016-06-29 19:45:50 PDT!

      5)shutdown -k并不会真正关机,仅仅是给各登录的用户发送提醒

[root@localhost xiong]# shutdown -k "Warning:Maybe the system will be shutdown."
Failed to parse time specification: Warning:Maybe the system will be shutdown.
[root@localhost xiong]# shutdown -k 5 "Warning:Maybe the system will be shutdown."
Shutdown scheduled for 三 2016-06-29 19:53:56 PDT, use 'shutdown -c' to cancel.
[root@localhost xiong]# 
Broadcast message from root@localhost.localdomain (Wed 2016-06-29 19:48:56 PDT):

Warning:Maybe the system will be shutdown.
The system is going down for power-off at Wed 2016-06-29 19:53:56 PDT!

      6)快速或慢速重启(Unbuntu有-f或-F参数,CentOS没有)

shutdown -f  [time]         //快速重启,忽略磁盘检查
shutdown -F  [time]         //强制磁盘检查

 5.其他:

      1)永久更改系统时间:

//date命令只能暂时更改系统时间,关机重启后时间又会回到之前,所以需要将时间写入bios
[root@localhost xiong]# date -s "2016-06-30 11:05:10"
 2016年 06月 30日 星期四 11:04:30 PDT
[root@localhost xiong]# clock -w

      2)显示机器的处理器架构:

[root@localhost xiong]# arch
x86_64

      3)其他关机命令:

init 0             //关机
init 6            //关机重启    
reboot            //关机重启

      4)clock与date命令:

//只有超级用户才能设置硬件时钟。
[xiong@localhost ~]$ su root                                  
密码:
[root@localhost xiong]# clock --set --date="05/04/2013 14:30:01"        //设置硬件时间为2013年
[root@localhost xiong]# clock
2013年05月04日 星期六 14时30分12秒  -0.388214 秒
[root@localhost xiong]# date                              //此时硬件时间为2013,系统时间为2016
2016年 06月 29日 星期三 20:20:36 PDT
[root@localhost xiong]# clock -s                           //根据硬件时间设置系统时间
[root@localhost xiong]# date
2013年 05月 04日 星期六 14:31:04 PDT
[root@localhost xiong]# clock
2013年05月04日 星期六 14时31分09秒  -0.101952 秒                    //系统时间和硬件时间都为2013年
[root@localhost xiong]# date -s "2016-06-30 11:22:10"                //设置系统时间为2016年
2016年 06月 30日 星期四 11:22:10 PDT
[root@localhost xiong]# clock                            //系统时间为2016年,硬件时间为2013
2013年05月04日 星期六 14时32分13秒  -0.559223 秒
[root@localhost xiong]# clock -w                           //根据系统时间设置硬件时间
[root@localhost xiong]# date
2016年 06月 30日 星期四 11:22:51 PDT
[root@localhost xiong]# clock
2016年06月30日 星期四 11时22分56秒  -0.968643 秒

      5)显示本机shell的信息,也可以更改shell

[xiong@localhost ~]$ chsh -l
/bin/sh
/bin/bash
/sbin/nologin
/usr/bin/sh
/usr/bin/bash
/usr/sbin/nologin
/bin/tcsh
/bin/csh
[xiong@localhost ~]$ chsh -v
chsh,来自 util-linux 2.23.2

 

转载于:https://www.cnblogs.com/shujuxiong/p/9013807.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值