『Linux学习』基本命令篇(三)

来源:互联网 发布:日漫中的中国知乎 编辑:程序博客网 时间:2024/05/19 04:03

1.检查磁盘空间

1)df   显示文件系统中的磁盘使用和空闲区的数量  -h选项以人类容易理解的方式列出每个文件系统的使用情况  -i是i节点的使用情况

2)du  显示磁盘的使用总量 以k字节为单位显示文件系统磁盘空间的使用的总量

[root@localhost zhao]# dfFilesystem           1K-blocks      Used Available Use% Mounted on/dev/sda2              8064304   6720040    934608  88% //dev/sda1               256666     18751    224663   8% /bootnone                    387260         0    387260   0% /dev/shm/dev/sda5              6119520     48780   5759884   1% /home
2.mount命令,执行磁盘等的挂载

[root@localhost zhao]# mount /dev/hdc /media/cdrom
挂载光驱到 /media/cdrom  不同设备对用的  /dev/hdc(设备文件)不同

eject 卸载  eject  /media/cdrom

3.以下是软盘的内容,由于现在软盘用的很好,简单介绍一些命令:

1)执行简单的格式化

[root@localhost zhao]# fdformat /dev/fd0H1440

2)高级格式化命令

  • mkfs  -t  ext2|ext3|vfat|    /dev/fd0
  • mke2fs  /dev/fd0

在格式化之前首先要卸载设备文件。

4.unix2dos和dos2unix命令

[root@localhost mypro]# unix2dos main.cppunix2dos: converting file main.cpp to DOS format ...[root@localhost mypro]# cat -A main.cpp#include<stdio.h>^M$int main()^M${^M$    printf("haha");^M$    return 0;^M$}^M$[root@localhost mypro]# dos2unix main.cppdos2unix: converting file main.cpp to UNIX format ...[root@localhost mypro]# cat -A main.cpp#include<stdio.h>$int main()${$    printf("haha");$    return 0;$}$

5.diff命令来比较两个文件的内容

1)<  表示第一个文件中的数据行

2)> 表示第二个文件中的数据行

如果文件中有空格时,要使用“  ”引起来

sdiff

1)|  左侧表示第一个文件中的数据行

2)| 右侧表示第二个文件中的数据行

3)< 表示第一个文件中的数据行(当第一个文件中有数据但是第二个文件中没有时)

4)> 表示第二个文件中的数据行(当第二个文件中有数据但是第一个文件中没有时)


aspell和look命令检查单词的拼法

aspell  check  文件名

expend 将TAB转成空格

[root@localhost ~]# expand test > test.space
将test中的TAB转换成空格

使用fmt和pr命令重新格式化正文


6.tar  归档文件和文件技术

tar命令中,归档文件名要使用相对路径

必须使用如下选项:

1)c:创建一个新的tar文件

2)t:列出tar文件中内容的目录

3)x:从tar文件中抽取文件

4)f:指定归档文件或磁带(也可能是软盘)设备(一般都要选)

tar可选的选项:

1)v:显示所打包的文件的详细信息。v是verbose的第一个字母。

2)z:使用gzip压缩算法来压缩打包后的文件。

3)j:使用bzip2压缩算法打包后的文件。

[root@localhost mypro]# tar cvf mytar main.cpp m
[root@localhost mypro]# tar tvf mytar

gzip命令

gzip  [选项]  [压缩文件名]

1)-v:在屏幕上显示出文件的压缩比

2)-c:保留原来的文件,而创建一个新的压缩文件,其中压缩文件名.gz结尾

而解压缩时,只要输入gunzip空一格之后紧跟着解压缩的文件即可。

直接使用tar命令将文件打包到软盘上的步骤

1)必须将使用的软盘进行低级格式化

2)不需要将磁盘格式化成文件系统

3)必须将软盘卸载

4)使用tar命令直接将文件打包到软盘上。

5)在tar命令中要使用软盘的设备名/dev/fd0,因为软盘已经被卸载掉了,所以不能使用软盘所对应的目录。

使用tar命令的M选项表示要分片打包备份

[root@localhost mypro]# tar cvfM /dev/fd0 arch

7.grep,egrep,fgrep命令来搜索文件中满足特定模式或字符串的内容。

  • c* :将匹配0个或者多个字符c
  • .  (点):将匹配任何一个字符而且只能是一个字符
  • [xyz] :将匹配方括号中的任意一个字符
  • [^ x y z ] :将匹配不包括方括号中的字符的所有字符。
  • ^ :锁定行的开头
  • $ :锁定行的结尾

元字符如 * ,+,{,|,(,),失去了原来的含义,需要进行转义。

grep命令是用来在每一个文件中标准输出上搜索特定的模式。


grep  选项    模式    文件名

  • -c:仅列出包含模式的行数
  • -i:忽略模式中字母的大小写
  • -l:列出带有匹配行文件的文件名
  • -n:在每行的最前面列出行号
  • -v:列出没有匹配模式的行
  • -w:把表达式作为一个完整的单字来搜寻,忽略那些部分匹配的行。

如果是搜寻多个文件,grep命令只显示在文本中发现匹配模式的文件名,而搜索的是单一的文件,grep命令的结果将显示每一个包含匹配模式的行。

egrep命令是用来在一个或多个文件的内容中利用扩展正则表达式的元字符搜索特定的模式。

  • +:匹配一个或多个前导字符
  • a|b:匹配a或b
  • (RE):匹配括号中的正则表达式RE

expand -t 1 emp 把emp中的TAB转换成一个空格 -t 1的含义

使用fgrep,搜索速度快,但是不支持搜索任何正则表达式,即将通配符当作普通字符来处理。

fgrep只能搜索确定的模式。可以使用-f指定匹配模式所在的文件。

[root@localhost mypro]# echo what i want search > condition[root@localhost mypro]# fgrep -f condition emp

8.sed命令搜索和替换字符。(shell编程时会详细说明)

sed  [选项]  命令表达式   输入文件

命令表达式格式   ‘s/ 旧模式/新模式/标志’  配置多个表达式可以用 ;分开

标志:

1)g:全局的

2)n:前n行

3)d:删除匹配的行

eg:

[root@localhost mypro]# sed '/^$/d;/cal/d;s/tie/fox/g' sedtest
第一个模式删除空行

第二个是参数含有cal的行

第三个是把tie替换成fox

sed ‘1,2d’ 删除1,2行

9.awk(shell编程时会详细说明)

awk  '{command}'

1)-F 指定分隔符

2)NF 字段数

3)$NF 最后一内容

4)NR用来跟踪所显示的数据的数目

5)$0,表示整个数据行

10.Bash Shell的配置与变量

1)利用局域变量来设定Bash Shell

2)通过别名和函数来设定Bash Shell

3)通过set命令来设定Bash Shell

4)通过环境变量来设定Bsah Shell中的其他命令和应用程序

shell变量是内存中一个命了名的临时存储区,在其中可以存放数字或者字符等信息,可以利用shell变量来设定shell或其他的程序,而且变量只存在于内存中

shell变量的特征:

1)shell变量分为两种,即局部变量和全局变量

2)局部变量只能在当前的工作环境中使用

3)环境变量不但可以在当前的工作shell中使用,而且会传给它的所有子shell

4)使用set命令显示的所有变量,其中包括局部变量和环境变量

5)使用evn命令显示的环境变量


创建shell局部变量的方法是:变量名=变量的值

[zhao@localhost ~]$ YYYY=LLLLLL

局部变量PS1:PS1变量主要是用来设置Bash shell提示符显示的信息的,也就是常常看到的$符号和它之前的信息

可以将一些换码序列插入到PS1变量中:

  • \d:系统当前的日期
  • \t:系统当前的时间
  • \h:简短的主机名
  • \u:当前用户名
  • \w:当前的工作目录
  • \!:当前命令的历史编号:
  • \$:当前普通用户显示$,而root用户显示#
  • \l:显示终端的基本名

[zhao@localhost ~]$ echo $PS1[\u@\h \W]\$[zhao@localhost ~]$ PS1='[\u@\h \w TTY\l \d \t \!]\$'[zhao@localhost ~ TTY1 Sat Nov 10 10:49:26 90]$

别名:alias 别名的名字=命令字符串

1)在等号的两边都不能有任何空格

2)如果命令字符串中包含任何选项,元字符,命令必须使用单引号括起来

3)在一个别名中的每一个命令必须用分号(;)隔开

取消别名和取消局部变量:

unalias 别名的名字

unset 变量的名字

[zhao@localhost ~]$set -o | moreallexport       offbraceexpand     onemacs           onerrexit         offerrtrace        offfunctrace       offhashall         onhistexpand      onhistory         onignoreeof       offinteractive-comments    onkeyword         offmonitor         onnoclobber       off

这个地方说明一下noclobber选项,如果将参数的noclobber的值开启为on,则意味着当使用>或>&操作符时,不会损坏已经存在的文件,也就是说当使用输出重定向符号>或>&时,如果>或>&右边的文件已经存在,系统将不会执行这一输出重定向命令,以保证已经不存在的文件不会遭破坏。这个为off时,对原有的文件执行覆盖。

将局部变量转化成环境变量:

export 变量名

由某个用户1通过su命令切换到用户2,用户1使用的shell叫做主shell,用户2使用的shell叫做子shell。

11.shell启动脚本和登录shell

shell启动脚本的作用包括4点:(Linux系统启动后立即执行的脚本)

  • 通过在启动脚本文件中设置局部变量或运行set命令来设置shell
  • 通过在启动脚本文件中建立环境变量来设置其他程序
  • 在启动脚本文件中创建(启用)别名
  • 在启动脚本文件中定义系统启动时要执行的程序。

登录shell和非登录shell

登录shell就是由用户登录的操作而触发的所运行的shell

即用户登录后所使用的shell。使用su - 用户名 切换

非登录shell通过以下方式:

  • 使用su 用户名命令 ,这里su命令没有 -
  • 使用图形终端
  • 执行脚本
  • 从一个shell启动的shell
loginshell的执行顺序:
1)执行/etc/profile这个启动脚本,在/etc/profile这个启动脚本中会调用/etc/profile.d目录下的所有脚本
2)执行~/.bash_profile(用户家目录的.bash_profile)这个启动脚本,在这个启动脚本中会调用~/.bashrc(用户家目录中的.bashrc)这个启动脚本。而~/.bashrc这个启动脚本会调用/etc/bashrc这个启动脚本。
non-login shell执行的启动脚本的顺序
将首先执行~/.bashrc(用户家目录中的.bashrc)脚本文件,而~/.bashrc脚本文件将调用/etc/bashrc这个脚本文件,当执行完了这两个脚本文件后,Non-login shell才会执行/etc/profile.d目录中的全部相关的脚本文件


只有loginshell启动时才会执行/etc/profile这个脚本,而Non-login shell不会调用这个脚本。
一些重要的变量都是存在这个脚本中的。
像PATH ,USER,LOGINNAME,HOSTNAME,MAIL,HISTSIZE.
在/etc/profile文件中设置的是全局变量.

~/.bash_profile和~/.bashrc:这个两个脚本文件中主要存放用户自己的一些设定,其中包括用户自定义的变量和别名,如果在登录时需要把输出的信息传送到屏幕上,那么应该将这些指令存放在~/.bash_profile文件中,而不要放在~/.bashrc文件中。

~/.bash_logout这个脚本也是存放在用户的家目录中的,每当用户推出系统时就会运行该脚本,它主要的作用是用户退出系统时,自动运行某些程序。

12.硬件设备和文件的对应关系
  • 块设备
  • 字符设备
主要有三种块设备
  • /dev/hda:IDE硬盘驱动器,其中hda中a是IDE的硬盘编号,如果有第二个IDE硬盘,将对应到/dev/hdb。如果这个硬盘被分区,那么每一个分区都会有一个编号:/dev/hda1,/dev/hda2
  • /dev/sda:SCSI硬盘驱动器,其中a是SCSI硬盘的编号。如果有第二个SCSI硬盘,将对应到文件/dev/sdb,如果这个硬盘被分区,那么每一个分区都会有一个编号:/dev/sda1,/dev/是da2
  • /dev/fd0:软盘驱动器
  • /dev/tty[0-7]:虚拟终端的窗口
  • /dev/st0:SCSI磁带机
[zhao@localhost ~]$ls -li /dev/tty[0-7] 471 crw-rw----  1 root root 4, 0 Nov 10 10:28 /dev/tty01908 crw-------  1 root root 4, 1 Nov 10 10:29 /dev/tty11909 crw-------  1 root root 4, 2 Nov 10 10:29 /dev/tty21910 crw-------  1 root root 4, 3 Nov 10 10:29 /dev/tty31911 crw-------  1 root root 4, 4 Nov 10 10:29 /dev/tty41912 crw-------  1 root root 4, 5 Nov 10 10:29 /dev/tty51913 crw-------  1 root root 4, 6 Nov 10 10:29 /dev/tty6 593 crw-rw----  1 root root 4, 7 Nov 10 10:28 /dev/tty7

上面的终端都是字符设备(c开头),他们并不使用数据块,因此也不需要大侠,在i节点中,存放大小的字段存放的是访问设备的设备号。
4是主设备号
0,1,2....7是辅助设备号

Linux操作系统就是根据主要的设备号来确定驱动程序的入口(使用哪个驱动程序),而Linux操作系统根据辅助的设备号来确定相同的驱动程序使用哪一个设备。

13.为什么使用磁盘分区。
1)更容易管理和控制系统,因为相关的文件和目录都放在一个分区中。
2)系统的效率更高。
3)可以限制用户使用硬盘的份额。
4)更容易备份和恢复。

MBR(Master Boot Record ) 主引导记录:(不属于任何分区,因此不对应Linux系统中的任何设备文件)
MBR被存储在第一个硬盘的第0磁道上,并且它的大小固定为512个字节
1)boot loader(自举引导程序或引导装加载分区),其大小固定为446字节,在boot loader中存放了开机多必须的信息,这些信息主要作用是要选择从哪个分区装入操作系统。如果安装了grub管理程序,grub的第一阶段的代码就会被存储在这里。
2)分区表。(partion table),其大小固定为64字节,在分区表中存放了每一个分区的起始磁柱和结束磁柱。,而记录每一个分区磁柱的所需空间固定为16个字节。
3)幻数。其大小为2个字节,存放了每一个bios的号。

14.系统启动的顺序:
Bios-->MBR--->kernal---->init

bios的初始化工作:
1)检查计算机硬件和外围设备,当bios一启动就会做一个自我检测的工作,也叫加电自检,以检测计算机上的硬件和外围设备,如CPU,内存
2)选择哪一个设备来开机
3)在选择了使用哪个设备来开机后,就会读取开机设备的第一个块,(也就是MBR)中的内容并执行这段代码。
接下来就是引导加载程序,可以安装在MBR上,也可以安装在开机硬盘的一个分区上。

15.GRUB(多重操作系统启动管理器)
1)具有一个命令行界面并可以在开机提示符下输入grub的命令
2)可以使用多种文件系统开机,其中包括ext2/ext3,FAT等文件系统
3)支持使用MD5加密技术以保护GRUB的密码。
4)GRUB的设置存放在/boot/grub/grub.conf配置文件中。
5)变更/boot/grub/grub.conf文件的内容会立即生效
6)如果硬盘上的MBR损坏了,可以使用/sbin/grub-install命令重新将boot loader安装到MBR中。

16.内核的初始化和init的初始化:
内核在开机阶段要做的主要操作
1)发现(检测)计算机上有哪些设备
2)发现设备后,将这些设备的驱动程序初始化并载入到内核中。
3)当必要的驱动程序都载入之后,以只读的方式挂载根目录文件系统
4)内核将载入Linux系统的第一个进程init进程,所以这个程序是第一个被执行的。

接下来有init进程接管系统,init进程首先要读取/etc/inittab文件中的设定,并根据这些设定来配置系统以完成系统的初始化。一下是init进程要做的:
1)决定预设系统使用哪个run level 
2)init执行一些系统初始化脚本来初始化系统。
3)init会根据run level 的设置来执行run level所对应目录中程序以决定要启动那些服务
4)设定某个组合键
5)定义UPS不间断电源系统。即当电源出现问题时,或电源恢复时,要执行那些程序。
6)产生5个虚拟终端控制台。

run level
[zhao@localhost ~]$more /etc/inittab## inittab       This file describes how the INIT process should set up#               the system in a certain run-level.## Author:       Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org>#               Modified for RHS Linux by Marc Ewing and Donnie Barnes## Default runlevel. The runlevels used by RHS are:#   0 - halt (Do NOT set initdefault to this)#   1 - Single user mode#   2 - Multiuser, without NFS (The same as 3, if you do not have networking)#   3 - Full multiuser mode#   4 - unused#   5 - X11#   6 - reboot (Do NOT set initdefault to this)#id:5:initdefault:# System initialization.si::sysinit:/etc/rc.d/rc.sysinitl0:0:wait:/etc/rc.d/rc 0l1:1:wait:/etc/rc.d/rc 1l2:2:wait:/etc/rc.d/rc 2l3:3:wait:/etc/rc.d/rc 3l4:4:wait:/etc/rc.d/rc 4l5:5:wait:/etc/rc.d/rc 5l6:6:wait:/etc/rc.d/rc 6

0:halt                              关机
1:single user mode                  单用户模式
2:multi-user without Network        不支持网络的多用户模式
3:full multi-user mode              完整的多用户模式
4:unused                            保留
5:X                                 x window模式
6:reboot                            重新启动

init要做的下一个工作:
它会执行一些系统的初始化脚本,来初始化系统,init就会执行/etc/rc.d目录中的rc.sysinit程序来初始化系统。
inti要做的第三个工作就是根据run level 的设置来执行所对应的目录中的程序,以决定要启动那些服务。如果默认设定是5,那么就会将5这个参数传递给/etc/rc.d,它的实际含义是执行/etc/rc.d/rc5.d目录中的所有程序。

17./etc/rc.d/rc.sysinit所做的工作。

1)启动激活热插拔设备,udev,如USB设备,并且会启动selinux
2)将内核Kernel的参数设定在/etc/sysctl.conf文件中
3)设定系统时钟
4)载入keymaps的设定,即定义键盘这样计算机就可以知道相对应的键位
5)启用交换分区这个虚拟分区
6)设定主机名,主机名实在/etc/sysconfig/network文件中设定的,这个文件是一个正文文件,可以使用cat命令来浏览内容。
7)检查root文件系统,也就是根目录,如果没有问题就将其重新挂载成可读可写的状态
8)启用RAID磁盘阵列和LVM设备。
9)启用磁盘配额功能,即限制用户最多可以使用多少磁盘空间。
10)检查并挂其他的文件系统。
11)清除开机时用的临时文件以及一些无用的目录和文件。

[zhao@localhost ~]$ls -l /etc/rc.dtotal 112drwxr-xr-x  2 root root  4096 Oct 17 12:44 init.d-rwxr-xr-x  1 root root  2352 Mar 17  2004 rcdrwxr-xr-x  2 root root  4096 Oct 17 20:44 rc0.ddrwxr-xr-x  2 root root  4096 Oct 17 20:44 rc1.ddrwxr-xr-x  2 root root  4096 Oct 17 20:44 rc2.ddrwxr-xr-x  2 root root  4096 Oct 17 20:44 rc3.ddrwxr-xr-x  2 root root  4096 Oct 17 20:44 rc4.ddrwxr-xr-x  2 root root  4096 Oct 17 20:44 rc5.ddrwxr-xr-x  2 root root  4096 Oct 17 20:44 rc6.d-rwxr-xr-x  1 root root   220 Jun 24  2003 rc.local-rwxr-xr-x  1 root root 28078 Oct 23  2006 rc.sysinit
只列小部分
[zhao@localhost ~]$ls -l /etc/rc.d/rc5.dtotal 476lrwxrwxrwx  1 root root 21 Oct 16 07:53 K01tog-pegasus -> ../init.d/tog-pegasuslrwxrwxrwx  1 root root 13 Oct 16 07:40 K01yum -> ../init.d/yumlrwxrwxrwx  1 root root 24 Oct 16 07:40 K02NetworkManager -> ../init.d/NetworkManagerlrwxrwxrwx  1 root root 17 Oct 16 08:04 K02oddjobd -> ../init.d/oddjobdlrwxrwxrwx  1 root root 14 Oct 16 08:03 K05innd -> ../init.d/inndlrwxrwxrwx  1 root root 19 Oct 16 07:39 K05saslauthd -> ../init.d/saslauthdlrwxrwxrwx  1 root root 19 Oct 16 07:41 K10dc_server -> ../init.d/dc_serverlrwxrwxrwx  1 root root 16 Oct 16 07:40 K10psacct -> ../init.d/psacctlrwxrwxrwx  1 root root 17 Oct 16 08:03 K10radiusd -> ../init.d/radiusdlrwxrwxrwx  1 root root 19 Oct 16 07:41 K12dc_client -> ../init.d/dc_clientlrwxrwxrwx  1 root root 17 Oct 16 08:02 K12FreeWnn -> ../init.d/FreeWnnlrwxrwxrwx  1 root root 17 Oct 16 08:02 K12mailman -> ../init.d/mailmanlrwxrwxrwx  1 root root 15 Oct 16 07:41 K15httpd -> ../init.d/httpd

18.守护进程:
守护进程就是在后台运行的一个程序,主要功能是提供一些系统服务。例如:vsftd,httpd。
守护进程的分类:
1)独立守护进程:(Standalone)
2)临时守护进程:(Transient),是有超级守护进程(super daemon)控制的守护进程。(提高系统的效率和资源利用率)

独立守护进程的工作方式是:
当用户或程序提出需求时,独立守护进程会自己为用户或程序提供所需的服务。
临时守护进程的工作方式是:
当用户或程序提出需求时,会向Xinetd超级守护进程要求服务,之后,Xinetd进程再调用相应的临时守护进程。最后再由这个守护进程为用户或程序提供服务。
Transient类的守护进程不能自己直接的向用户或程序提供服务,必须要通过Xinetd超级进程的调用,而独立进程则不需要。

Linux的独立进程分两种:
1)在开机时由init进程直接启动的,如虚拟终端控制台
2)System V的守护进程。例如:httpd 和vsftpd

[zhao@localhost ~]$ls -l /etc/rc.d/rc5.dtotal 476lrwxrwxrwx  1 root root 21 Oct 16 07:53 K01tog-pegasus -> ../init.d/tog-pegasuslrwxrwxrwx  1 root root 13 Oct 16 07:40 K01yum -> ../init.d/yumlrwxrwxrwx  1 root root 24 Oct 16 07:40 K02NetworkManager -> ../init.d/NetworkManagerlrwxrwxrwx  1 root root 17 Oct 16 08:04 K02oddjobd -> ../init.d/oddjobdlrwxrwxrwx  1 root root 14 Oct 16 08:03 K05innd -> ../init.d/inndlrwxrwxrwx  1 root root 19 Oct 16 07:39 K05saslauthd -> ../init.d/saslauthdlrwxrwxrwx  1 root root 19 Oct 16 07:41 K10dc_server -> ../init.d/dc_serverlrwxrwxrwx  1 root root 16 Oct 16 07:40 K10psacct -> ../init.d/psacctlrwxrwxrwx  1 root root 17 Oct 16 08:03 K10radiusd -> ../init.d/radiusdlrwxrwxrwx  1 root root 19 Oct 16 07:41 K12dc_client -> ../init.d/dc_clientlrwxrwxrwx  1 root root 17 Oct 16 08:02 K12FreeWnn -> ../init.d/FreeWnnlrwxrwxrwx  1 root root 17 Oct 16 08:02 K12mailman -> ../init.d/mailmanlrwxrwxrwx  1 root root 15 Oct 16 07:41 K15httpd -> ../init.d/httpdlrwxrwxrwx  1 root root 15 Oct 16 08:03 K16rarpd -> ../init.d/rarpdlrwxrwxrwx  1 root root 20 Oct 16 08:02 K20bootparamd -> ../init.d/bootparamdlrwxrwxrwx  1 root root 24 Oct 16 08:03 K20netdump-server -> ../init.d/netdump-serverlrwxrwxrwx  1 root root 13 Oct 16 07:40 K20nfs -> ../init.d/nfslrwxrwxrwx  1 root root 16 Oct 16 08:02 K20rstatd -> ../init.d/rstatdlrwxrwxrwx  1 root root 17 Oct 16 08:02 K20rusersd -> ../init.d/rusersdlrwxrwxrwx  1 root root 15 Oct 16 08:02 K20rwhod -> ../init.d/rwhodlrwxrwxrwx  1 root root 14 Oct 16 07:40 K24irda -> ../init.d/irdalrwxrwxrwx  1 root root 15 Oct 16 07:41 K25squid -> ../init.d/squidlrwxrwxrwx  1 root root 13 Oct 16 08:04 K28amd -> ../init.d/amdlrwxrwxrwx  1 root root 22 Oct 16 07:45 K30spamassassin -> ../init.d/spamassassinlrwxrwxrwx  1 root root 18 Oct 16 08:03 K34dhcrelay -> ../init.d/dhcrelaylrwxrwxrwx  1 root root 19 Oct 16 08:03 K34yppasswdd -> ../init.d/yppasswddlrwxrwxrwx  1 root root 21 Oct 16 08:02 K35cyrus-imapd -> ../init.d/cyrus-imapdlrwxrwxrwx  1 root root 15 Oct 16 08:03 K35dhcpd -> ../init.d/dhcpdlrwxrwxrwx  1 root root 17 Oct 16 08:02 K35dovecot -> ../init.d/dovecotlrwxrwxrwx  1 root root 13 Oct 16 07:41 K35smb -> ../init.d/smblrwxrwxrwx  1 root root 19 Oct 16 07:42 K35vncserver -> ../init.d/vncserverlrwxrwxrwx  1 root root 17 Oct 16 08:23 K35winbind -> ../init.d/winbindlrwxrwxrwx  1 root root 16 Oct 16 08:03 K36dhcp6s -> ../init.d/dhcp6slrwxrwxrwx  1 root root 14 Oct 16 07:59 K36lisa -> ../init.d/lisalrwxrwxrwx  1 root root 16 Oct 16 08:03 K36mysqld -> ../init.d/mysqldlrwxrwxrwx  1 root root 20 Oct 16 08:03 K36postgresql -> ../init.d/postgresqllrwxrwxrwx  1 root root 18 Oct 16 08:20 K45arpwatch -> ../init.d/arpwatchlrwxrwxrwx  1 root root 15 Oct 16 08:03 K46radvd -> ../init.d/radvdlrwxrwxrwx  1 root root 16 Oct 16 07:40 K50ibmasm -> ../init.d/ibmasmlrwxrwxrwx  1 root root 17 Oct 16 07:40 K50netdump -> ../init.d/netdumplrwxrwxrwx  1 root root 15 Oct 16 07:41 K50snmpd -> ../init.d/snmpdlrwxrwxrwx  1 root root 19 Oct 16 07:41 K50snmptrapd -> ../init.d/snmptrapdlrwxrwxrwx  1 root root 13 Oct 16 07:41 K50tux -> ../init.d/tuxlrwxrwxrwx  1 root root 16 Oct 16 08:01 K50vsftpd -> ../init.d/vsftpdlrwxrwxrwx  1 root root 14 Oct 16 08:03 K61ldap -> ../init.d/ldaplrwxrwxrwx  1 root root 16 Oct 16 08:03 K65kadmin -> ../init.d/kadminlrwxrwxrwx  1 root root 15 Oct 16 08:03 K65kprop -> ../init.d/kproplrwxrwxrwx  1 root root 16 Oct 16 08:03 K65krb524 -> ../init.d/krb524lrwxrwxrwx  1 root root 17 Oct 16 08:03 K65krb5kdc -> ../init.d/krb5kdclrwxrwxrwx  1 root root 16 Oct 16 08:23 K73ypbind -> ../init.d/ypbindlrwxrwxrwx  1 root root 14 Oct 16 08:23 K74nscd -> ../init.d/nscdlrwxrwxrwx  1 root root 14 Oct 16 08:52 K74ntpd -> ../init.d/ntpdlrwxrwxrwx  1 root root 16 Oct 16 08:03 K74ypserv -> ../init.d/ypservlrwxrwxrwx  1 root root 16 Oct 16 08:03 K74ypxfrd -> ../init.d/ypxfrdlrwxrwxrwx  1 root root 14 Oct 16 08:02 K84bgpd -> ../init.d/bgpdlrwxrwxrwx  1 root root 16 Oct 16 08:02 K84ospf6d -> ../init.d/ospf6dlrwxrwxrwx  1 root root 15 Oct 16 08:02 K84ospfd -> ../init.d/ospfdlrwxrwxrwx  1 root root 14 Oct 16 08:02 K84ripd -> ../init.d/ripdlrwxrwxrwx  1 root root 16 Oct 16 08:02 K84ripngd -> ../init.d/ripngdlrwxrwxrwx  1 root root 15 Oct 16 07:40 K85mdmpd -> ../init.d/mdmpdlrwxrwxrwx  1 root root 15 Oct 16 08:02 K85zebra -> ../init.d/zebralrwxrwxrwx  1 root root 16 Oct 16 07:39 K87auditd -> ../init.d/auditdlrwxrwxrwx  1 root root 14 Oct 17 20:44 K87ipmi -> ../init.d/ipmilrwxrwxrwx  1 root root 20 Oct 16 08:04 K87multipathd -> ../init.d/multipathdlrwxrwxrwx  1 root root 15 Oct 16 08:01 K87named -> ../init.d/namedlrwxrwxrwx  1 root root 15 Oct 16 08:02 K89iscsi -> ../init.d/iscsilrwxrwxrwx  1 root root 18 Oct 16 07:39 K89netplugd -> ../init.d/netplugdlrwxrwxrwx  1 root root 19 Oct 16 07:40 K90bluetooth -> ../init.d/bluetoothlrwxrwxrwx  1 root root 18 Oct 16 07:40 K94diskdump -> ../init.d/diskdumplrwxrwxrwx  1 root root 23 Oct 16 07:40 S00microcode_ctl -> ../init.d/microcode_ctllrwxrwxrwx  1 root root 17 Oct 16 08:04 S01sysstat -> ../init.d/sysstatlrwxrwxrwx  1 root root 25 Oct 16 07:40 S04readahead_early -> ../init.d/readahead_earlylrwxrwxrwx  1 root root 15 Oct 16 07:39 S05kudzu -> ../init.d/kudzulrwxrwxrwx  1 root root 17 Oct 16 07:40 S05openibd -> ../init.d/openibdlrwxrwxrwx  1 root root 18 Oct 16 07:40 S06cpuspeed -> ../init.d/cpuspeedlrwxrwxrwx  1 root root 22 Oct 16 08:04 S08arptables_jf -> ../init.d/arptables_jflrwxrwxrwx  1 root root 19 Oct 16 08:02 S08ip6tables -> ../init.d/ip6tableslrwxrwxrwx  1 root root 18 Oct 16 07:40 S08iptables -> ../init.d/iptableslrwxrwxrwx  1 root root 14 Oct 16 07:40 S09isdn -> ../init.d/isdnlrwxrwxrwx  1 root root 16 Oct 16 07:40 S09pcmcia -> ../init.d/pcmcialrwxrwxrwx  1 root root 17 Oct 16 07:39 S10network -> ../init.d/networklrwxrwxrwx  1 root root 16 Oct 16 07:39 S12syslog -> ../init.d/sysloglrwxrwxrwx  1 root root 20 Oct 16 07:40 S13irqbalance -> ../init.d/irqbalancelrwxrwxrwx  1 root root 17 Oct 16 07:40 S13portmap -> ../init.d/portmaplrwxrwxrwx  1 root root 17 Oct 16 07:40 S14nfslock -> ../init.d/nfslocklrwxrwxrwx  1 root root 19 Oct 16 07:40 S15mdmonitor -> ../init.d/mdmonitorlrwxrwxrwx  1 root root 19 Oct 16 07:40 S18rpcidmapd -> ../init.d/rpcidmapdlrwxrwxrwx  1 root root 17 Oct 16 07:40 S19rpcgssd -> ../init.d/rpcgssdlrwxrwxrwx  1 root root 14 Oct 16 08:04 S24o2cb -> ../init.d/o2cblrwxrwxrwx  1 root root 15 Oct 16 07:39 S25netfs -> ../init.d/netfslrwxrwxrwx  1 root root 15 Oct 16 08:04 S25ocfs2 -> ../init.d/ocfs2lrwxrwxrwx  1 root root 14 Oct 16 07:40 S26apmd -> ../init.d/apmdlrwxrwxrwx  1 root root 20 Oct 16 07:41 S26lm_sensors -> ../init.d/lm_sensorslrwxrwxrwx  1 root root 16 Oct 16 07:40 S28autofs -> ../init.d/autofslrwxrwxrwx  1 root root 19 Oct 16 08:04 S29oracleasm -> ../init.d/oracleasmlrwxrwxrwx  1 root root 17 Oct 17 12:43 S30vboxadd -> ../init.d/vboxaddlrwxrwxrwx  1 root root 21 Oct 17 20:44 S30vboxadd-x11 -> ../init.d/vboxadd-x11lrwxrwxrwx  1 root root 25 Oct 17 12:44 S35vboxadd-service -> ../init.d/vboxadd-servicelrwxrwxrwx  1 root root 16 Oct 16 07:40 S40smartd -> ../init.d/smartdlrwxrwxrwx  1 root root 15 Oct 16 07:40 S44acpid -> ../init.d/acpidlrwxrwxrwx  1 root root 14 Oct 16 07:41 S54hpoj -> ../init.d/hpojlrwxrwxrwx  1 root root 14 Oct 16 07:40 S55cups -> ../init.d/cupslrwxrwxrwx  1 root root 14 Oct 16 07:40 S55sshd -> ../init.d/sshdlrwxrwxrwx  1 root root 20 Oct 16 07:39 S56rawdevices -> ../init.d/rawdeviceslrwxrwxrwx  1 root root 16 Oct 16 07:40 S56xinetd -> ../init.d/xinetdlrwxrwxrwx  1 root root 18 Oct 16 07:40 S80sendmail -> ../init.d/sendmaillrwxrwxrwx  1 root root 13 Oct 16 07:40 S85gpm -> ../init.d/gpmlrwxrwxrwx  1 root root 14 Oct 16 08:00 S87iiim -> ../init.d/iiimlrwxrwxrwx  1 root root 15 Oct 16 08:01 S90canna -> ../init.d/cannalrwxrwxrwx  1 root root 15 Oct 16 07:40 S90crond -> ../init.d/crondlrwxrwxrwx  1 root root 13 Oct 16 07:41 S90xfs -> ../init.d/xfslrwxrwxrwx  1 root root 17 Oct 16 07:40 S95anacron -> ../init.d/anacronlrwxrwxrwx  1 root root 13 Oct 16 07:40 S95atd -> ../init.d/atdlrwxrwxrwx  1 root root 19 Oct 16 07:40 S96readahead -> ../init.d/readaheadlrwxrwxrwx  1 root root 20 Oct 16 07:39 S97messagebus -> ../init.d/messagebuslrwxrwxrwx  1 root root 15 Oct 16 07:40 S97rhnsd -> ../init.d/rhnsdlrwxrwxrwx  1 root root 28 Oct 16 07:41 S98cups-config-daemon -> ../init.d/cups-config-daemonlrwxrwxrwx  1 root root 19 Oct 16 07:39 S98haldaemon -> ../init.d/haldaemonlrwxrwxrwx  1 root root 11 Oct 16 07:39 S99local -> ../rc.local

解释一下这个列表,这里面全都是连接,这写连接名称里主要分3部分:
1)第一部分:以K或者S开头,以K开头表示要停用连接的服务,以S开头表示启动这些服务。K和S先执行K,先停用服务的连接,然后再执行S启动。
2)第二部分数字代表的是顺序,越小的先执行
3)服务的名字,
先把系统复位,把所有的服务停掉,然后再启动。

System V守护进程的有一个特性,就是启动和停用都是使用一个脚本,只是在脚本程序后面假山不同的参数。(start,stop,status)
[root@localhost ~]# /etc/init.d/vsftpd statusvsftpd is stopped[root@localhost ~]# /etc/init.d/vsftpd startStarting vsftpd for vsftpd:                                [  OK  ][root@localhost ~]# /etc/init.d/vsftpd statusvsftpd (pid 5475) is running...

看上面的最长的最后一个是/rc.local ,99表示最后执行,可以修改rc.local,将run level 2-5都要执行的指令或程序设定在这个文件中。

19.管理和维护服务
1)ntsysv:可以修改开机启动项,默认这修改当前level的服务设置,但是通过使用--level选项可以修改其他run level的设置了
例如:我想修改在run level 3,5下的开机启动项
ntsysv --level 35
[root@localhost ~]# chkconfig --listnfslock         0:off   1:off   2:off   3:on    4:on    5:on    6:offpostgresql      0:off   1:off   2:off   3:off   4:off   5:off   6:offnetdump         0:off   1:off   2:off   3:off   4:off   5:off   6:offvboxadd-x11     0:off   1:off   2:off   3:on    4:off   5:on    6:offypbind          0:off   1:off   2:off   3:off   4:off   5:off   6:offcpuspeed        0:off   1:on    2:on    3:on    4:on    5:on    6:offhaldaemon       0:off   1:off   2:off   3:on    4:on    5:on    6:offnfs             0:off   1:off   2:off   3:off   4:off   5:off   6:off

2)chkconfig --list :
3)system-config-service

Linux系统可以使用以下三个工具来手动控制服务的停止和启动:
(立即改变这种状态)
1)service:可以立即启动和停用独立类型的服务。
2)chkconfig:可以立即启动和停用Xinetd超级守护进程所管理的服务。
3)system-config-service:

20.系统关机:
1)shutdown -h now :now是时间,now表示立即。
2)halt:与shutdown相同,但是可以加参数,-n参数表示在关机之前不做同步的操作。
3)poweroff:
4)init 0;
这四个命令都会自定运行sync命令来同步系统,sync命令的功能是强制将内存中已经变化的数据块和超级数据块写回硬盘中。

原创粉丝点击