Linux关闭和重启系统
Linux关闭和重启系统
在Linux系统下常用在关机/重启命令有shutdown、halt、reboot和init,但每个命令的内部工作过程是不同的。
1.shutdown命令
Shutdown命令可以安全地关闭系统,有些用户会使用直接断电源的方式来关闭计算机,这是十分危险的。
Linux与Windows不同,其后台运行着许多进程,所以强制关机可能会导致进程的数据丢失,使系统处于不稳定的状态,在有的系统中甚至会损坏硬件设备。
如果在系统关机前使用shutdown命令,系统管理员会通知所有登录的用户系统将要关闭,并且login命令会被冻结,即新的用户不能再登录。
直接关机或者延迟一定的时间才关机都是可能的,还可能重启。
shutdown命令可以安全地关闭或重启Linux系统,它在系统关闭之前给系统上的所有登录用户提示一条警告信息。
该命令还允许用户指定一个时间参数,此参数可以是一个精确的时间,也可以是从现在开始的一个时间段。
精确时间的格式是hh:mm,表示小时和分钟,时间段由“+”和分钟数表示。
系统执行该命令后,会自动进行数据同步的工作。
(1)语法
shutdown[选项][时间][警告信息]
(2)选项说明
-k:并不真正关机,只是发出警告信息给所有用户
-r:关机后立即重新启动
-h:关机后不重新启动
-f:快速关机,重启动时跳过fsck
-n:快速关机,不经过init程序
-c:取消一个已经运行的shutdown
[-time]:设定关机前的时间
(3)例:立即关闭系统
#shutdown–h now
(4)例:定时45min后关闭系统
#shutdown–h45
(5)例:重新启动系统,并发出警告信息
#shutdown–r now“system will be reboot now!”
2.halt命令
其实halt命令就是调用“shutdown-h”命令执行的。
(1)语法
halt[选项]
(2)选项说明
-c:防止sync系统调用,它用在fsck修补根分区之后,以阻止内核用老版本的超级块覆盖修补过的超级块
-w:并不是真正的重启或关机,只是写wtmp(/var/log/wtmp)记录
-d:不写wtmp记录(已包含在选项[-n]中)
-f:没有调用shutdown而强制关机或重启
-I:关机(或重启)前,关掉所有的网络接口
-p:该选项为缺省选项,即关机时调用poeroff
(3)例:使用halt命令关机
#halt
Broadcast message from root(pts/4)….
The system is going down for system halt now!
3.reboot命令
Reboot的工作过程与halt相似,不过reboot是引发主机重启,而halt是引发主机关机。
它的参数与halt相似。
(1)例:使用reboot命令重启计算机
#reboot
Broadcast message from root(pts/4)….
The system is going down for system reboot now!
4.init命令
Init是所有进程的祖先,它的进程号始终为1,所以发送TREM信号给init会终止所有的用户进程和守护进程等。
shutdown就是使用这种机制。
init定义了7个运行级别,其中init0为关机,init为重启。
linux reboot的流程
linux reboot的流程下载温馨提示:该文档是我店铺精心编制而成,希望大家下载以后,能够帮助大家解决实际的问题。
文档下载后可定制随意修改,请根据实际需要进行相应的调整和使用,谢谢!并且,本店铺为大家提供各种各样类型的实用资料,如教育随笔、日记赏析、句子摘抄、古诗大全、经典美文、话题作文、工作总结、词语解析、文案摘录、其他资料等等,如想了解不同资料格式和写法,敬请关注!Download tips: This document is carefully compiled by theeditor. I hope that after you download them,they can help yousolve practical problems. The document can be customized andmodified after downloading,please adjust and use it according toactual needs, thank you!In addition, our shop provides you with various types ofpractical materials,such as educational essays, diaryappreciation,sentence excerpts,ancient poems,classic articles,topic composition,work summary,word parsing,copy excerpts,other materials and so on,want to know different data formats andwriting methods,please pay attention!Linux 重启流程。
1. 触发重启命令。
可以使用以下命令触发 Linux 重启:`reboot`。
linux reboot的用法
linux reboot的用法Linux是一种非常流行的操作系统,而reboot是其中一个重要的命令。
reboot用于重新启动计算机系统。
在本文中,我将介绍reboot命令的用法以及如何正确地使用它。
首先,我们需要明确一点,reboot命令需要root用户或具有root权限的用户才能执行。
这是因为重新启动计算机可能会造成未保存的数据丢失,所以需要特定权限来执行该命令。
要使用reboot命令,只需要在终端中输入reboot并按下回车键即可。
系统会立即开始重新启动过程。
请注意,在执行该命令之前,请确保你已保存好所需的文件和数据,并关闭所有正在运行的应用程序,以免造成数据丢失。
有时,你可能希望在计划时间后执行重新启动操作。
对此,reboot命令提供了一个选项:-d。
通过在reboot命令后添加-d选项,可以设置一个延迟时间(以秒为单位),系统将在该时间到达后重新启动。
例如,如果你希望系统在10分钟后重新启动,可以输入以下命令:reboot -d 600此外,reboot命令还有其他一些选项可供选择。
例如,-f选项可用于强制重启系统而无需确认。
这在某些情况下可能很有用,但务必小心使用,以免造成数据损坏。
还有一个选项是-k,它会向所有用户发送一个警告消息,告知系统将重新启动,并暂停新的登录。
这对于在重新启动之前通知用户很有用。
总而言之,reboot命令是一个重要的命令,用于重新启动Linux操作系统。
在使用该命令之前,请确保你已保存好所需的文件和数据,并关闭所有正在运行的应用程序。
另外,还要注意使用命令的特定选项,以满足你的需求。
希望本文对你理解并正确使用reboot命令有所帮助。
如有任何疑问,请随时提问。
Linux终端中的系统关机和重启命令
Linux终端中的系统关机和重启命令Linux作为一种开源的操作系统,具有很高的灵活性和自定义性。
在使用Linux终端时,系统关机和重启是经常涉及到的操作。
本文将介绍Linux终端中常用的系统关机和重启命令,供用户参考和使用。
1. 关机命令在Linux终端中,通过使用特定的关机命令可以实现系统的安全关机,保证数据的完整性,避免出现数据丢失或损坏的情况。
下面是常用的关机命令及其用法:1.1. shutdown命令shutdown命令可实现系统的关机操作,并向所有登录用户发送关机通知。
命令格式如下:```shutdown [选项] 时间 [警告信息]```常用选项:- -r: 关机后立即重启系统- -h: 关机后不重启系统- -c: 取消已经设置的关机操作- -t seconds: 设置关机前的等待时间(以秒为单位)示例:```shutdown -h now # 立即关机shutdown -h +10 # 10分钟后关机shutdown -r 20:00 # 指定时间关机并重启shutdown -c # 取消当前关机操作```1.2. poweroff命令poweroff命令负责关闭电源,可以用来执行硬件完全关机,对电源断电。
命令格式如下:```poweroff```示例:```poweroff```1.3. halt命令halt命令用于停止系统运行,并使计算机进入停止状态。
命令格式如下:```halt```示例:```halt```1.4. init命令init命令用于改变系统的运行等级,其中运行等级0为关机状态,通常用init命令实现关机操作。
命令格式如下:```init [运行等级]```示例:```init 0```2. 重启命令有时候需要重启系统以应用修改或解决一些问题。
在Linux终端中,可以使用以下命令实现系统的重启:2.1. reboot命令reboot命令用于重启系统,它会关闭所有正在运行的进程,并重新引导计算机。
Linux终端中的系统启动和关机命令
Linux终端中的系统启动和关机命令Linux作为一个开源的操作系统,具有强大的灵活性和自定义性。
在Linux终端中,我们可以使用一些命令来控制系统的启动和关机。
本文将详细介绍一些常用的系统启动和关机命令,并探讨它们的功能和使用方法。
一、系统启动命令1. rebootreboot命令用于重新启动系统。
在终端中输入reboot后,系统将会立即重启。
这个命令非常有用,尤其是在需要迅速重启系统的情况下,如在安装软件或更新内核后。
2. shutdownshutdown命令用于正常关机系统。
默认情况下,输入shutdown命令后系统将在一分钟后执行关机操作。
如果需要设置关机时间,可以使用“shutdown -h now”命令来立即关机,或者使用“shutdown -h +分钟数”命令来设置延迟关机的时间。
除了关机命令,shutdown还可以用于重启系统。
例如,使用“shutdown -r now”命令将会立即重启系统。
3. initinit命令是Linux系统的初始化命令,用于切换系统的运行级别。
运行级别是电脑中一种特定的工作状态,对应着一组特定的功能服务。
Linux系统共有七个运行级别,分别是0-6。
其中,0表示关机,6表示重启。
要切换运行级别,可以使用“init 数字”命令进行操作。
例如,“init 3”将将系统切换到文本模式,而“init 5”则进入图形模式。
二、系统关机命令1. halthalt命令用于立即关机系统。
它会发送一个信号给内核,告诉系统立即关闭。
输入“halt”命令后,系统将会停止所有进程并关机。
2. poweroffpoweroff命令用于正常关机系统。
它会先发送一个信号给所有运行的进程,告诉它们系统即将关机。
这个命令会在关机前允许进程的保存和关闭操作,确保数据的完整性。
3. init在上一节中我们已经介绍了init命令的用途。
当我们使用“init 0”或“init 6”命令时,系统将会执行关机或重启操作。
Linux关机命令分析
Linux关机命令分析linux下有关关机重启的命令主要有:shutdown、reboot、halt、poweroff、telinit、init。
它们都可以达到关机或重启的目的,但是每个命令的工作流程并不一样。
它们都由软件包sysvinit生成,你可以从网上下载它的源码来分析各个命令的流程,同时,sysvinit也包含了与登陆等有关的命令。
下面分析sysvinit-2.86软件包的源码,同时参考它们的手册来对它们深入了解。
1、从Makefile可以知道,上面的命令并不都是互相独立的,poweroff、reboot是halt 的链接,telinit是init的链接。
ln -sf halt $(ROOT)/sbin/rebootln -sf halt $(ROOT)/sbin/poweroffln -sf init $(ROOT)/sbin/telinit在终端输入# ls -l /sbin/poweroff# ls -l /sbin/reboot# ls -l /sbin/telinit也可以看到上面的结果。
2、halt。
参数说明:[-n] 防止sync系统调用﹐它用在用fsck修补根分区之后﹐以阻止内核用老版本的超级块〔superblock〕覆盖修补过的超级块。
[-w] 并不是真正的重启或关机﹐只是写wtmp〔/var/log/wtmp〕纪录。
[-d] 不写wtmp纪录〔已包含在选项[-n]中〕。
[-f] 没有调用shutdown而强制关机或重启(halt/reboot)。
[-h] 使硬盘处于standby模式。
[-i] 关掉所有的网络接口。
[-p] 该选项为缺省选项。
就是关机时调用poweroff。
前面已经知道,poweroff、reboot是halt的链接,halt会首先判断用户执行的是否是poweroff和reboot中的一个。
如果执行的是poweroff,则等效于-p参数,执行reboot 的情况将在下面说明。
linux虚拟机关机、重启命令
linux虚拟机关机、重启命令linux虚拟机关机、重启命令⼀.shutdown1.shutdown -h now :⽴即关机2.shutdown -h 10:53:到10:53关机3.shutdown -h +10 :10分钟后⾃动关机4.shutdown -r :重启(默认30秒)5.shutdown -r now :⽴即重启6.shutdown -r +30 :’The System Will Reboot 30 in Mins’:30分钟后重启并发送通知给其他在线⽤户7.shutdown -s -t 100 :延迟100秒关机8.shutdown -a :取消上⾯的关机、重启⼆、reboot1.reboor :重启,相当于shutdown -r now2.reboot -d :重新启动时不把数据写⼊记录⽂件 /var/tmp/wtmp3.reboot -f :强制重新开机4.reboot -h:在系统关机之前,将所有的硬盘处于待机模式下5.reboot -i :关闭⽹络设置之后再重新启动系统6.reboot -n :保存数据后重启三、halt1.halt :关机2.halt -d :关闭系统,不把记录写到/var/log/wtmp⽂件⾥3.halt -p :关机并关闭电源4.halt -f :强制关机四、init1.init 0 :关机2.0-6:表⽰系统运⾏的7个级别0:关机级别1:单⽤户级别,运⾏rc.sysinit和rc1.d⽬录下的脚本2:多⽤户,但系统不会启动NFS,字符模式3:多⽤户,字符模式,系统启动具有⽹络功能4:⽤户⾃定义级别5:图形界⾯模式6:重启级别五、poweroff1.poweroff :关机并关闭电源2.poweroff -p:关机并关闭电源3.poweroff -f :强制关机4.poweroff -w:不是真正的关机,只是将数据写⼊到/var/log/wtmp⽂件⾥六、按Ctrl + Alt + Delete键—- 选择关机。
linux服务器关机、重启、注销命令
linux服务器关机、重启、注销命令管理员root用户下执行命令。
1关机命令 shutdown好像ubuntu的终端中默认的是当前用户的命令,只是普通用户,因此在终端器中可以使用sudo -sh 转换到管理员root用户下执行命令。
1)shutdown –help可以查看shutdown命令如何使用,当然也可以使用man shutdown命令。
2) shutdown -h now 现在立即关机 3)shutdown -r now 现在立即重启 4)shutdown -r +3 三分钟后重启5)shutdown -h +3 “The System will shutdown after 3 minutes”提示使用者将在三分钟后关机6)shutdown -r 20:23 在20:23时将重启计算机7)shutdown -r 20:23 & 可以将在20:23时重启的任务放到后台去,用户可以继续操作终端2中断命令1)执行完命令后(若没有转到后台),可以使用CTRL+C来中止命令 2)kill 程序编码当命令在后台执行时系统会返回一个程序编码,例如:在使用 shutdown -r 20:23 & 系统返回系统编码:4905我们可以使用kill 4905来中止重启命令 3ps aux | grep 程序编号我们如果知道程序的编号,我们可以使用ps aux |grep 程序编号来查询该程序编号对应的命令是什么。
例如上面的程序编号为4905 ,我们可以使用ps aux | grep 4905 就可以查到 shutdown -r 20:23 & 的命令halt—-最简单的关机命令其实halt就是调用shutdown -h。
halt执行时﹐杀死应用进程﹐执行sync系统调用﹐文件系统写操作完成后就会停止内核。
参数说明:[-n] 防止sync系统调用﹐它用在用fsck修补根分区之后﹐以阻止内核用老版本的超级块〔superblock〕覆盖修补过的超级块。
linux的shutdown命令详解
linux的shutdown命令详解linux下关机我们可以采用shutdown命令来实现,下面由店铺为大家搜集整理了linux的shutdown命令详解的相关知识,希望对大家有帮助!linux的shutdown命令详解命令简介:该命令可以安全关闭或者重新启动系统。
你没有看错,shutdown 命令不仅可以关闭系统、也可以重启Linux系统。
命令语法:/sbin/shutdown [-t sec] [-arkhncfFHP] time [warning-message]命令参数:参数长参数描叙-a Use /etc/shutdown.allow.-c中断关机:当执行"shutdown -h 12:00"指令时,只要按+键就可以中断关机的指令-f重新启动时不进行磁盘检测(fsck)-F重新启动时进行磁盘检测(fsck)-h关闭电源-k模拟关机(不是真的关机),只是向登录者发送警告信息出去!-n不调用init进程进行关机,而是强行关机-r关闭系统然后重新启动,类似于Windows平台restart-t延迟关机的时间-w仅做测试,并不真的将系统重新开机,只会把重开机的数据写入/var/log目录下的wtmp记录文件--help显示命令在线帮助linux的shutdown命令使用示例1: 查看reboot命令的帮助信息[root@db-server ~]# shutdown --helpshutdown: invalid option -- -Usage: shutdown [-akrhHPfnc] [-t secs] time [warning message]-a: use /etc/shutdown.allow-k: don't really shutdown, only warn.-r: reboot after shutdown.-h: halt after shutdown.-P: halt action is to turn off power.-H: halt action is to just halt.-f: do a 'fast' reboot (skip fsck).-F: Force fsck on reboot.-n: do not go through "init" but go down real fast.-c: cancel a running shutdown.-t secs: delay between warning and kill signal.** the "time" argument is mandatory! (try "now") **[root@db-server ~]#[root@db-server ~]# man shutdownSHUTDOWN(8) Linux System Administrator鈥檚Manual SHUTDOWN(8)NAMEshutdown - bring the system downSYNOPSIS/sbin/shutdown [-t sec] [-arkhncfFHP] time [warning-message]DESCRIPTIONshutdown brings the system down in a secure way. All logged-in users are notified that the system is going down, and login(1) is blocked. It is possible to shut the system down immediately or after a specified delay.All processes are first notified that the system is going down by the signal SIGTERM. This gives programs likevi(1) the time to save the file being edited, mail and news processing programs a chance to exit cleanly, etc.shutdown does its job by signalling the init process, asking it to change the runlevel. Runlevel 0 is used tohalt the system, runlevel 6 is used to reboot the system, and runlevel 1 is used to put to system into a statewhere administrative tasks can be performed; this is the default if neither the -h or -r flag is given to shut-down. To see which actions are taken on halt or reboot see the appropriate entries for these runlevels in thefile /etc/inittab.OPTIONS-a Use /etc/shutdown.allow.-t sec Tell init(8) to wait sec seconds between sending processes the warning and the kill signal, beforechanging to another runlevel.-k Don鈥檛really shutdown; only send the warning messages to everybody.-r Reboot after shutdown.-h Halt or poweroff after shutdown.-H Halt action is to halt or drop into boot monitor on systems that support it.-P Halt action is to turn off the power.-n [DEPRECATED] Don鈥檛call init(8) to do the shutdown but do it ourself. The use of this option is dis-couraged, and its results are not always what you鈥檇 expect.-f Skip fsck on reboot.-F Force fsck on reboot.-c Cancel an already running shutdown. With this option it is of course not possible to give the time argu-ment, but you can enter a explanatory message on the command line that will be sent to all users.time When to shutdown.warning-messageMessage to send to all users.The time argument can have different formats. First, it can be an absolute time in the format hh:mm, in whichhh is the hour (1 or 2 digits) and mm is the minute of the hour (in two digits). Second, it can be in the for-mat +m, in which m is the number of minutes to wait. The word now is an alias for +0.If shutdown is called with a delay, it creates the advisory file /etc/nologin which causes programs such aslogin(1) to not allow new user logins. Shutdown removes this file if it is stopped before it can signal init(i.e. it is cancelled or something goes wrong). It also removes it before calling init to change the runlevel.The -f flag means 鈥榬eboot fast鈥? This only creates an advisory file /fastboot which can be tested by the sys- tem when it comes up again. The boot rc file can test if this file is present, and decide not to run fsck(1)since the system has been shut down in the proper way. Afterthat, the boot process should remove /fastboot.The -F flag means 鈥榝orce fsck鈥? This only creates an advisory file /forcefsck which can be tested by the sys- tem when it comes up again. The boot rc file can test if this file is present, and decide to run fsck(1) witha special 鈥榝orce鈥?flag so that even properly unmounted filesystems get checked. After that, the boot process should remove /forcefsck.The -n flag causes shutdown not to call init, but to kill all running processes itself. shutdown will thenturn off quota, accounting, and swapping and unmount all filesystems.ACCESS CONTROLshutdown can be called from init(8) when the magic keys CTRL-ALT-DEL are pressed, by creating an appropriate entry in /etc/inittab. This means that everyone who has physical access to the console keyboard can shut the system down. T o prevent this, shutdown can check to see if an authorized user is logged in on one of the vir-tual consoles. If shutdown is called with the -a argument (add this to the invocation of shutdown in /etc/init-tab), it checks to see if the file /etc/shutdown.allow is present. It then compares the login names in thatfile with the list of people that are logged in on a virtual console (from /var/run/utmp). Only if one of thoseauthorized users or root is logged in, it will proceed. Otherwise it will write the messageshutdown: no authorized users logged into the (physical) system console. The format of /etc/shutdown.allow is one user name per line. Empty lines andcomment lines (prefixed by a #) are allowed. Currently there is a limit of 32 users in this file.Note that if /etc/shutdown.allow is not present, the -a argument is ignored.HALT OR POWEROFFThe -H option just sets the init environment variable INIT_HALT to HALT, and the -P option just sets that vari- able to POWEROFF. The shutdown script that calls halt(8) as the last thing in the shutdown sequence shouldcheck these environment variables and call halt(8) with the right options for these options to actually haveany effect. Debian 3.1 (sarge) supports this.FILES/fastboot/etc/inittab/etc/init.d/halt/etc/init.d/reboot/etc/shutdown.allowNOTESA lot of users forget to give the time argument and are then puzzled by the error message shutdown produces.The time argument is mandatory; in 90 percent of all cases this argument will be the word now.Init can only capture CTRL-ALT-DEL and start shutdown in console mode. If the system is running the X window System, the X server processes all key strokes. Some X11 environments make it possible to capture CTRL-ALT-DEL, but what exactly is done with that event depends on that environment.Shutdown wasn鈥檛designed to be run setuid./etc/shutdown.allow is not used to find out who is executing shut-down, it ONLY checks who is currently logged in on (one of the) console(s).AUTHORMiquelvanSmoorenburg,******************SEE ALSOfsck(8), init(8), halt(8), poweroff(8), reboot(8)November 12, 2003 SHUTDOWN(8)(END)2:马上关闭Linux系统,其中 now 相当于时间为 0 的状态[root@db-server ~]# shutdown -h nowBroadcast message from root (pts/1) (Sat Jan 10 18:51:34 2015):The system is going down for system halt NOW!3:系统2分钟后重新启动,其中+m表示几分钟后关机或开机。
CentOS常用基础命令大全(linux命令)
CentOS常⽤基础命令⼤全(linux命令)1.关机 (系统的关机、重启以及登出 ) 的命令shutdown -h now 关闭系统(1)init 0 关闭系统(2)telinit 0 关闭系统(3)shutdown -h hours:minutes & 按预定时间关闭系统shutdown -c 取消按预定时间关闭系统shutdown -r now 重启(1)reboot 重启(2)logout 注销2.查看系统信息的命令arch 显⽰机器的处理器架构(1)uname -m 显⽰机器的处理器架构(2)uname -r 显⽰正在使⽤的内核版本dmidecode -q 显⽰硬件系统部件 - (SMBIOS / DMI)hdparm -i /dev/hda 罗列⼀个磁盘的架构特性hdparm -tT /dev/sda 在磁盘上执⾏测试性读取操作cat /proc/cpuinfo 显⽰CPU info的信息cat /proc/interrupts 显⽰中断cat /proc/meminfo 校验内存使⽤cat /proc/swaps 显⽰哪些swap被使⽤cat /proc/version 显⽰内核的版本cat /proc/net/dev 显⽰⽹络适配器及统计cat /proc/mounts 显⽰已加载的⽂件系统lspci -tv 罗列 PCI 设备lsusb -tv 显⽰ USB 设备date 显⽰系统⽇期cal 2007 显⽰2007年的⽇历表date 0412********.00 设置⽇期和时间 - ⽉⽇时分年.秒clock -w 将时间修改保存到 BIOS3.⽂件和⽬录操作命令cd /home 进⼊ '/ home' ⽬录'cd .. 返回上⼀级⽬录cd ../.. 返回上两级⽬录cd 进⼊个⼈的主⽬录cd ~user1 进⼊个⼈的主⽬录cd - 返回上次所在的⽬录pwd 显⽰⼯作路径ls 查看⽬录中的⽂件ls -F 查看⽬录中的⽂件ls -l 显⽰⽂件和⽬录的详细资料ls -a 显⽰隐藏⽂件mkdir dir1 创建⼀个叫做 'dir1' 的⽬录'mkdir dir1 dir2 同时创建两个⽬录mkdir -p /tmp/dir1/dir2 创建⼀个⽬录树rm -f file1 删除⼀个叫做 'file1' 的⽂件'rmdir dir1 删除⼀个叫做 'dir1' 的⽬录'rm -rf dir1 删除⼀个叫做 'dir1' 的⽬录并同时删除其内容rm -rf dir1 dir2 同时删除两个⽬录及它们的内容mv dir1 new_dir 重命名/移动⼀个⽬录cp file1 file2 复制⼀个⽂件cp dir/* . 复制⼀个⽬录下的所有⽂件到当前⼯作⽬录cp -a /tmp/dir1 . 复制⼀个⽬录到当前⼯作⽬录cp -a dir1 dir2 复制⼀个⽬录ln -s file1 lnk1 创建⼀个指向⽂件或⽬录的软链接ln file1 lnk1 创建⼀个指向⽂件或⽬录的物理链接touch file1 创建⼀个⽂件4.⽂件搜索命令find / -name file1 从 '/' 开始进⼊根⽂件系统搜索⽂件和⽬录find / -user user1 搜索属于⽤户 'user1' 的⽂件和⽬录find /home/user1 -name \*.bin 在⽬录 '/ home/user1' 中搜索带有'.bin' 结尾的⽂件find /usr/bin -type f -atime +100 搜索在过去100天内未被使⽤过的执⾏⽂件find /usr/bin -type f -mtime -10 搜索在10天内被创建或者修改过的⽂件locate \*.ps 寻找以 '.ps' 结尾的⽂件 - 先运⾏ 'updatedb' 命令whereis file 显⽰⼀个⼆进制⽂件、源码或man的位置which file 显⽰⼀个⼆进制⽂件或可执⾏⽂件的完整路径5.查看⽂件内容cat file1 从第⼀个字节开始正向查看⽂件的内容tac file1 从最后⼀⾏开始反向查看⼀个⽂件的内容more file1 查看⼀个长⽂件的内容less file1 类似于 'more' 命令,但是它允许在⽂件中和正向操作⼀样的反向操作head -2 file1 查看⼀个⽂件的前两⾏tail -2 file1 查看⼀个⽂件的最后两⾏ 5.挂载命令mount /dev/hda2 /mnt/hda2 挂载⼀个叫做hda2的盘(注:确定⽬录 '/ mnt/hda2' 已经存在)umount /dev/hda2 卸载⼀个叫做hda2的盘(先从挂载点 '/ mnt/hda2' 退出)fuser -km /mnt/hda2 当设备繁忙时强制卸载umount -n /mnt/hda2 运⾏卸载操作⽽不写⼊ /etc/mtab ⽂件(当⽂件为只读或当磁盘写满时⾮常有⽤)mount /dev/fd0 /mnt/floppy 挂载⼀个软盘mount /dev/cdrom /mnt/cdrom 挂载⼀个光盘mount /dev/hdc /mnt/cdrecorder 挂载⼀个cdrw或dvdrommount /dev/hdb /mnt/cdrecorder 挂载⼀个cdrw或dvdrommount -o loop file.iso /mnt/cdrom 挂载⼀个⽂件或ISO镜像⽂件mount -t vfat /dev/hda5 /mnt/hda5 挂载⼀个Windows FAT32⽂件系统mount /dev/sda1 /mnt/usbdisk 挂载⼀个usb 捷盘或闪存设备mount -t smbfs -o username=user,password=pass //WinClient/share /mnt/share 挂载⼀个windows⽹络共享6.磁盘空间操作的命令df -h 显⽰已经挂载的分区列表ls -lSr |more 以尺⼨⼤⼩排列⽂件和⽬录du -sh dir1 估算⽬录 'dir1' 已经使⽤的磁盘空间'du -sk * | sort -rn 以容量⼤⼩为依据依次显⽰⽂件和⽬录的⼤⼩7.⽤户和群组相关命令groupadd group_name 创建⼀个新⽤户组groupdel group_name 删除⼀个⽤户组groupmod -n new_group_name old_group_name 重命名⼀个⽤户组useradd -c "Name Surname " -g admin -d /home/user1 -s /bin/bash user1 创建⼀个属于 "admin" ⽤户组的⽤户useradd user1 创建⼀个新⽤户userdel -r user1 删除⼀个⽤户 ( '-r' 同时删除除主⽬录)passwd user1 修改⼀个⽤户的⼝令 (只允许root执⾏)chage -E 2005-12-31 user1 设置⽤户⼝令的失效期限ls -lh 显⽰权限chmod 777 directory1 设置⽬录的所有⼈(u)、群组(g)以及其他⼈(o)以读(r )、写(w)和执⾏(x)的权限chmod 700 directory1 删除群组(g)与其他⼈(o)对⽬录的读写执⾏权限chown user1 file1 改变⼀个⽂件的所有⼈属性,为use1。
Linux关闭和重启的命令
Linux关闭和重启的命令概要:Linux中常用的关机和重启命令有shutdown、init、halt、reboot、poweroff和telinit,它们都可以达到关机和重新启动的目的,但是每个命令的内部工作过程是不同的,下面将逐一进行介绍。
本文以CentOS5.4 Linux为测试操作系统,所有示例均来自测试系统。
文中所述内容适用于Redhat Linux,但并不适用于所有版本的Linux。
1.各个命令之间的关系shutdown、init、halt、reboot、poweroff和telinit命令都存在于/sbin目录下,我们使用“ls -l”命令查看一下各个命令之间的关系。
如图1。
图1 各个命令之间的关系从图1中我们可以知道,各个命令之间并不都是相互独立的,poweroff和reboot是halt的符号链接,telinit是init的符号链接。
2.shutdown命令语法:shutdown [-krhfnc] [-t secs] time [warning message]只有root用户才有权限执行此命令,因为用户执行shutdown命令时,shutdown会调用getuid判断是否为root用户,如果为普通用户,则会退出。
有些用户会使用直接断掉电源的方式来关闭Linux,这是十分危险的。
因为Linux与Windows不同,其后台运行着许多进程,所以强制关闭机器可能会导致进程的数据丢失,使系统处于不稳定的状态,甚至会损坏硬件设备。
shutdown命令用于安全关闭Linux系统,它在系统关闭之前给系统上的所有登录用户提示一条警告信息。
该命令还允许用户指定一个时间参数,可以是一个精确的时间,也可以是从现在开始的一个时间段。
从语法中,我们可以看到time选项不可以省略。
time选项用于设置多久时间后执行shutdown命令。
time选项的值有hh:mm或+m两种模式。
hh:mm格式表示在几点几分执行shutdown命令。
