Linux基础命令-shutdown
shutdown
shutdown指令以安全的⽅式来关闭系统,所有已经登录的⽤户都会被告知系统将要关闭。
并且在最后五分钟内,新的登录将被阻⽌。
过了指定的time后,关机会向init(8)守护进程发送⼀个请求,以便将系统降⾄适当的运⾏级别。
这是通过发出runlevel(7)事件来执⾏的,该事件包括RUNLEVEL环境变量中的新运⾏级以及PREVLEVEL变量中的前⼀个运⾏级(从环境
或/var/run/utmp获得)。
可以设置⼀个额外的INIT_HART变量,它将包含使⽤halt指令关机的HAL 值,或者使⽤power off指令关机的POWEROFF值。
此命令的适⽤范围:RedHat、RHEL、Ubuntu、CentOS、SUSE、openSUSE、Fedora。
1、语法
shutdown [选项] [时间] [警告信息]
2、选项列表
选项说明
-c取消正在执⾏的关机,这个选项没有时间参数
-h关闭计算机,等于halt或者power off
-P等价power off
-H等价halt
-k只是发出警告信息,注销登录,并没有 关机
-r重启,等于reboot
时间now代表⽴刻关机; +m代表m分钟后关闭; 23:00代表在晚
上11点关机
3、说明
如果设置为⾸选从/var/run/utmp 读取RUNLEVEL ,关机将从此环境变量读取当前运⾏级。
“/var/run/utmp”⽂件,读取当前运⾏级的位置,该⽂件还将使⽤新的运⾏级别进⾏更新。
“/var/log/wtmp”⽂件,新运⾏级记录将追加到此⽂件中。
Upstart init(8)守护进程不跟踪运⾏级别本⾝,⽽是完全由其⽤户空间⼯具实现。
4、实例
1)5分钟后关闭机器,并发出警告“I am downing”
[root@192 /]# shutdown -h +5 I am downing //当前操作有root⽤户发出,5分钟后关机,并且有提⽰信息
Broadcast message from root@192.168.0.113
(/dev/pts/1) at 10:40 ...
The system is going down for halt in 5 minutes! //5分钟
I am downing//⾃定义的提⽰信息
[weijie@192 root]$ //当前控制台是weijie⽤户登录,他也收到关机信息
Broadcast message from root@192.168.0.113
(/dev/pts/1) at 10:40 ...
The system is going down for halt in 5 minutes!
I am downing
2)取消关机
[root@192 ~]# shutdown –c//需要打开另⼀个终端,输⼊取消命令[root@192 /]# shutdown -h +5 I am downing //在之前的关机命令窗⼜,最后可以看到取消的信息
…
The system is going down for halt in 4 minutes!
I am downing
shutdown: Shutdown cancelled
[root@192 /]#。
linuxshutdown命令以及参数详解
linuxshutdown命令以及参数详解
在说shutdown命令之前
先说⼀下sync命令:
sync:将内存中尚未写⼊硬盘的数据写⼊硬盘
因为linux为了保证数据读写速度,把常⽤的数据放在内存中,不会⽴即写⼊硬盘,如果有不当关机,这些数据就会丢失
所以在执⾏shutdown、reboot之类的命令之前,应当多执⾏⼏次sync命令来保证数据不丢失(虽然shutdown和reboot命令执⾏之后会⾃动执⾏sync,但是还是⼩⼼⼀些为好)
shutdown命令:
可搭配参数:
-t :后⾯跟数字,也就是“⼏秒之后关机”的意思,单位是秒(除了此指令后⾯的数字单位是秒,其他指令后⾯数字单位都是分钟,)-k :不是真正的关机,但是会向当前所有在线⽤户发送指令后⾯跟着的语句“语句⽤单引号包裹”(其他指令后⾯默认可以跟随语句——不过我试了⼀下好像没⽤?⽹上也没有找到资料,等接触到了再来更新~)
-r :将系统服务停⽌之后重启机器
-h :关掉系统服务之后⽴即关机(后⾯可以跟上数字,单位是分钟,也可以跟指令执⾏时刻,格式为xx:xx)
-n :不经过init程序,直接通过shutdown命令关机(此处对于init程序理解不是很深,需要重新学习)
-f :关机并且开机之后强制略过fsck磁盘检查
-F :系统重启之后,强制进⾏fsck磁盘检查
-c :取消已经在进⾏的shutdown命令内容(撤销关机——但是对于t参数为0或者now的关机指令不起作⽤)
常⽤的就是"sync;sync; sudo shutdown -h now"
也就是将内存内数据写⼊硬盘之后⽴即关机的意思。
linux下最常用的关机命令 -回复
linux下最常用的关机命令-回复Linux是一种开源的操作系统,广泛用于服务器和个人电脑。
关机是每个电脑用户都会经历的过程,而在Linux中,也有一些常用的命令来完成关机操作。
本文将一步一步回答"Linux下最常用的关机命令"这一主题。
一、通过命令行关闭电脑在Linux中,我们可以通过命令行来控制关机。
以下是最常用的几个关机命令:1. 关机命令:shutdown- 语法:shutdown [选项] [时间] [警告消息]- 示例:shutdown -h now- 解释:这个命令会立即关闭计算机,并向所有用户发送一条关机警告消息。
2. 重启命令:reboot- 语法:reboot- 示例:reboot- 解释:这个命令会重启计算机,关闭所有的进程,并重新启动系统。
3. 立即关机命令:poweroff- 语法:poweroff- 示例:poweroff- 解释:这个命令会立即关闭计算机,无论是否有未保存的数据。
4. 取消关机命令:halt- 语法:halt- 示例:halt- 解释:这个命令会关闭计算机,但不会切断电源。
使用这个命令可以安全地关闭计算机,而不会丢失数据。
5. 指定关机时间命令:shutdown- 语法:shutdown [选项] 时间- 示例:shutdown -h 10:30- 解释:这个命令会在指定的时间(10:30)关机。
二、关机命令的选项和参数除了上述常用的关机命令外,关机命令还支持一些选项和参数,以满足用户不同的需求。
1. 选项- -h:关机后断电。
- -r:关机后重新启动。
- -c:取消关机操作。
- -k:仅向所有用户发送关机警告消息,而不进行真正的关机操作。
2. 时间参数- now:立即关机。
- +m:在m分钟内关机。
- hh:mm:在指定的时刻关机。
三、使用示例以下是一些实际示例,演示如何使用关机命令来完成关机操作。
1. 立即关机:- 命令:shutdown -h now- 解释:立即关闭计算机,并向所有用户发送关机警告消息。
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系统下常⽤在关机/重启命令有shutdown、halt、reboot和init,但每个命令的内部⼯作过程是不同的。
1、shutdown命令Shutdown命令可以安全地关闭系统,有些⽤户会使⽤直接断电源的⽅式来关闭计算机,这是⼗分危险的。
Linux与Windows不同,其后台运⾏着许多进程,所以强制关机可能会导致进程的数据丢失,使系统处于不稳定的状态,在有的系统中甚⾄会损坏硬件设备。
如果在系统关机前使⽤shutdown命令,系统管理员会通知所有登录的⽤户系统将要关闭,并且login命令会被冻结,即新的⽤户不能再登录。
直接关机或者延迟⼀定的时间才关机都是可能的,还可能重启。
语法:shutdown [选项] [时间] [警告信息]选项说明: -k:并不真正关机,只是发出警告信息给所有⽤户 -r:关机后⽴即重新启动 -h:关机后不重新启动 -f:快速关机,重启动时跳过fsck -n:快速关机,不经过init程序 -c:取消⼀个已经运⾏的shutdown[-time]:设定关机前的时间举例:1)⽴即关闭系统:shutdown -h now2)定时45min后关闭系统:shutdown -h 453)重新启动系统,并发出警告信息:shutdown –r now“system will be reboot now!”2、halt命令halt命令就是调⽤“shutdown-h”命令执⾏的语法:halt [选项]选项说明: -c:防⽌sync系统调⽤,它⽤在fsck修补根分区之后,以阻⽌内核⽤⽼版本的超级块覆盖修补过的超级块 -w:并不是真正的重启或关机,只是写wtmp(/var/log/wtmp)记录 -d:不写wtmp记录(已包含在选项[-n]中) -f:没有调⽤shutdown⽽强制关机或重启 -I:关机(或重启)前,关掉所有的⽹络接⼝ -p:该选项为缺省选项,即关机时调⽤poweroff3、reboot命令Reboot的⼯作过程与halt相似,不过reboot是引发主机重启,⽽halt是引发主机关机。
linux系统下重启系统、关闭系统、注销系统等相关命令操作
linux系统下重启系统、关闭系统、注销系统等相关命令操作1.KDE快捷键1.KDE快捷键Alt+F1--弹出KDE菜单Alt+F2--弹出“运行"窗口2.用户注销在文字终端中,可以通过下面两种方式:.Exit或Logout.Ctrl+D组合键3.Linux操作系统的关闭与重启init 0:关机,且如果处于多用户模式,不会通知其他用户halt:与init 0类似,但它不会关闭计算机,用户可以Resetshutdown +10:10分钟后关闭计算机shutdown 23:00--23:00关闭计算机,无广播1.shutdownshutdown命令安全地将系统关机。
有些用户会使用直接断掉电源的方式来关闭linux,这是十分危险的。
因为linux与windows不同,其后台运行着许多进程,所以强制关机可能会导致进程的数据丢失o使系统处于不稳定的状态o甚至在有的系统中会损坏硬件设备。
而在系统关机前使用shutdown命令o系统管理员会通知所有登录的用户系统将要关闭。
并且login指令会被冻结o即新的用户不能再登录。
直接关机或者延迟一定的时间才关机都是可能的o还可能重启。
这是由所有进程〔process〕都会收到系统所送达的信号〔signal〕决定的。
这让像vi之类的程序有时间储存目前正在编辑的文档o而像处理邮件〔mail〕和新闻〔news〕的程序则可以正常地离开等等。
shutdown执行它的工作是送信号〔signal〕给init程序o要求它改变runlevel。
Runlevel 0被用来停机〔halt〕orunlevel 6是用来重新激活〔reboot〕系统o而runlevel 1则是被用来让系统进入管理工作可以进行的状态r这是预设的o假定没有-h也没有-r参数给shutdown。
要想了解在停机〔halt〕或者重新开机〔reboot〕过程中做了哪些动作o你可以在这个文件/etc/inittab 里看到这些runlevels相关的资料。
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服务器关机、重启、注销命令管理员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命令。
