Linux关机命令

摘要:
1.shutdownshutdown命令可安全关闭系统。一些用户会通过直接断开电源来关闭Linux,这非常危险。由于Linux与Windows不同,后台运行的进程很多,因此强制关闭可能会导致进程数据丢失,使系统处于不稳定状态,甚至会损坏某些系统中的硬件设备。当在系统关闭之前使用shutdown命令时,系统管理员将通知所有登录用户系统即将关闭。

man shutdown:

shutdown(8)                                                        shutdown(8)



NAME
       shutdown - bring the system down

SYNOPSIS
       shutdown [OPTION]...  TIME [MESSAGE]

DESCRIPTION
       shutdown arranges for the system to be brought down in a safe way.  All
       logged-in users are notified that the system is going down and,  within
       the last five minutes of TIME, new logins are prevented.

       TIME  may  have  different  formats, the most common is simply the word
       'now' which will bring the system down immediately.  Other  valid  for‐
       mats  are  +m,  where m is the number of minutes to wait until shutting
       down and hh:mm which specifies the time on the 24hr clock.

       Once TIME has elapsed, shutdown sends a request to the  init(8)  daemon
       to bring the system down into the appropriate runlevel.

       This is performed by emitting the runlevel(7) event, which includes the
       new runlevel in the RUNLEVEL environment variable as well as the previ‐
       ous  runlevel  (obtained from the environment or from /var/run/utmp) in
       the PREVLEVEL variable.  An additional INIT_HALT variable may  be  set,
       this will contain the value HALT when bringing the system down for halt
       and POWEROFF when bringing the system down for power off.

OPTIONS
       -r     Requests that the system be rebooted after it has  been  brought
              down.

       -h     Requests  that  the system be either halted or powered off after
              it has been brought down, with the choice as to which left up to
              the system.

       -H     Requests  that  the  system  be halted after it has been brought
              down.

       -P     Requests that the system  be  powered  off  after  it  has  been
              brought down.

       -c     Cancels  a  running  shutdown.   TIME is not specified with this
              option, the first argument is MESSAGE.

       -k     Only send out the warning messages and disable  logins,  do  not
              actually bring the system down.

ENVIRONMENT
       RUNLEVEL
              shutdown  will  read  the current runlevel from this environment
              variable if set in preference to reading from /var/run/utmp

FILES
       /var/run/utmp
              Where the current runlevel will be read  from;  this  file  will
              also be updated with the new runlevel.

       /var/log/wtmp
              A  new runlevel record will be appended to this file for the new
              runlevel.

NOTES
       The Upstart init(8) daemon does not keep  track  of  runlevels  itself,
       instead they are implemented entirely by its userspace tools.

       See runlevel(7) for more details.

 
SEE ALSO
       runlevel(7) init(8) telinit(8) reboot(8)



Upstart                           2009-07-09                       shutdown(8)

1 我想立即关机!

$shutdown -h now

2 我想立即重启

$shutdown -r now

3 我想在23:30分准时关机

$shutdown -h 23:30

4 我想在15分钟后关机

$shutdown -h +15

5 总结一下,你可以看到,如果想让shutdown干活,你必须告诉shutdown命令一个时间,无论是now,还是23:30,还是+15。

6 我想来个恶作剧!

恶作剧,就是吓唬用户。这个功能其实很实用,如果你是管理员,你完全可以利用“恶作剧”提醒所有登录的用户,让他们尽快退出程序,你要关机了。

来看看怎么搞“恶作剧”:

$shutdown -k now “Server would shutdown in 15minutes!”

看到了吧 加上-k选项就可以了 这样shutdown命令就知道这个命令只是一个恶作剧,不会真去关机的。shutdown会将你设定的消息字符串发给已登录的所有用户,这样就起到了提示的作用。试试-k吧!take it easy!

over~

    在linux下一些常用的关机/重启命令有shutdown、halt、reboot、及init,它们都 
可以达到重启系统的目的,但每个命令的内部工作过程是不同的,通过本文的介绍,希 
望你可以更加灵活的运用各种关机命令。 
   1.shutdown 
   shutdown命令安全地将系统关机。 有些用户会使用直接断掉电源的方式来关闭linux, 
这是十分危险的。因为linux与windows不同,其后台运行着许多进程,所以强制关机可能 
会导致进程的数据丢失﹐使系统处于不稳定的状态﹐甚至在有的系统中会损坏硬件设备。 
    而在系统关机前使用shutdown命令﹐系统管理员会通知所有登录的用户系统将要关闭。 
且login指令会被冻结﹐即新的用户不能再登录。直接关机或者延迟一定的时间才关机 
都是可能的﹐还可能重启。这是由所有进程〔process〕都会收到系统所送达的信号〔signal〕 
决定的。这让像vi之类的程序有时间储存目前正在编辑的文档﹐而像处理邮件〔mail〕和 
新闻〔news〕的程序则可以正常地离开等等。 
    shutdown执行它的工作是送信号〔signal〕给init程序﹐要求它改变runlevel。 
Runlevel 0被用来停机〔halt〕﹐runlevel 6是用来重新激活〔reboot〕系统﹐ 
而runlevel 1则是被用来让系统进入管理工作可以进行的状态﹔这是预设的﹐假定没有-h也 
没有-r参数给shutdown。要想了解在停机〔halt〕或者重新开机〔reboot〕过程中做了哪些 
动作﹐你可以在这个文件/etc/inittab里看到这些runlevels相关的资料。 
   shutdown 参数说明: 
   [-t] 在改变到其它runlevel之前﹐告诉init多久以后关机。 
   [-r] 重启计算器。 
   [-k] 并不真正关机﹐只是送警告信号给每位登录者〔login〕。 
   [-h] 关机后关闭电源〔halt〕。 
   [-n] 不用init﹐而是自己来关机。不鼓励使用这个选项﹐而且该选项所产生的后果往 
往不总是你所预期得到的。 
   [-c] cancel current process取消目前正在执行的关机程序。所以这个选项当然没有 
时间参数﹐但是可以输入一个用来解释的讯息﹐而这信息将会送到每位使用者。 
   [-f] 在重启计算器〔reboot〕时忽略fsck。  
     [-F] 在重启计算器〔reboot〕时强迫fsck。 
   [-time] 设定关机〔shutdown〕前的时间。 
      
2.halt----最简单的关机命令 
   其实halt就是调用shutdown -h。halt执行时﹐杀死应用进程﹐执行sync系统调用﹐ 
文件系统写操作完成后就会停止内核。 
   参数说明: 
   [-n] 防止sync系统调用﹐它用在用fsck修补根分区之后﹐以阻止内核用老版本的超 
级块〔superblock〕覆盖修补过的超级块。 
   [-w] 并不是真正的重启或关机﹐只是写wtmp〔/var/log/wtmp〕纪录。 
   [-d] 不写wtmp纪录〔已包含在选项[-n]中〕。 
   [-f] 没有调用shutdown而强制关机或重启。 
   [-i] 关机〔或重启〕前﹐关掉所有的网络接口。 
   [-p] 该选项为缺省选项。就是关机时调用poweroff。 
    
3.reboot 
    reboot的工作过程差不多跟halt一样﹐不过它是引发主机重启﹐而halt是关机。它 
    的参数与halt相差不多。 
4.init 
   init是所有进程的祖先﹐它的进程号始终为1﹐所以发送TERM信号给init会终止所有的 
   用户进程﹑守护进程等。shutdown 就是使用这种机制。init定义了8个运行级别(runlevel), 
   init 0为关机﹐init 1为重启。关于init可以长篇大论﹐这里就不再叙述。另外还有 
   telinit命令可以改变init的运行级别﹐比如﹐telinit -iS可使系统进入单用户模式﹐ 
   并且得不到使用shutdown时的信息和等待时间。  

参考:http://fanqiang.chinaunix.net/a1/b1/20020130/21030661.html

免责声明:文章转载自《Linux关机命令》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇C# xml 转 list 对象Kali Linux下的软件安装下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

linux 下dd命令直接清除分区表(不用再fdisk一个一个的删除啦)

分区表是硬盘的分区信息,要删除一个硬盘的所有分区表很麻烦的,需要fdisk一个一个的删除,其实dd命令可直接清除分区信息,当然,这也是linux给root用户留下的作死方法之一。dd 命令主要参数如下if= in file 输入文件,linux下文件的概念应用范围相当广,通常是普通光盘镜像文件或者块设备of= out file 输出文件,通常是普通光盘镜像...

linux环境安装opencv导入依赖报错问题

linux环境通过pip安装opencv后,导入cv2时报错: 在centos和ubuntu环境下都遇到相同的问题。报错原因: 缺少共享库有两种解决办法:一.使用如下命令查看缺少得共享库yum whatprovides libSM.so.6使用以下命令解决:yum install libSM-1.2.2-2.el7.x86_64 --setopt=prot...

Linux IO中BIO和DIO【转】

转自:https://blog.csdn.net/notbaron/article/details/77823158 转自: http://linuxperformance.top/index.php/archives/89/ Linux IO中BIO和DIO 作者: yanyun  时间: September 3, 2017  分类: Storage...

Linux命令学习笔记2

<1>ps -eaf: 1 ps -eaf |grep tomcat |grep -v grep >/dev/null 2>&1 分为4段 1、ps -eaf 查看当前进程,-e 显示所有进程,a显示终端上的所有进程,包括其他用户的进程,f 全格式。 2、显示的结果通过管道“|”传给第二段 grep tomcat,查找tom...

Linux上的oracle巡检脚本

修改自大神博客:http://www.cnblogs.com/jyzhao/p/5364049.html 脚本巡检的优化:自动化,节省时间。 脚本需加强:巡检结果中有大量的sqlplus连接信息,后期考虑用shell只过滤出有用信息,优化查看。 开始介绍: 1.环境sentos67、redhat6 2.可以将脚本放至/home/oracle/checkdi...

linux命令ps aux|grep xxx详解

对进程进行监测和控制,首先必须要了解当前进程的情况,也就是需要查看当前进程, 而ps命令(Process Status)就是最基本同时也是非常强大的进程查看命令. 使用该命令 可以确定有哪些进程正在运行和运行的状态、进程是否结束、进程有没有僵尸、哪些进程占用了过多的资源等等.总之大部分信息都是可以通过执行该命令得到的. ps 为我们提供了进程的一次性的查看...