『Linux學習』基本命令篇(三)

1.檢查磁盤空間

1)df   顯示文件系統中的磁盤使用和空閒區的數量  -h選項以人類容易理解的方式列出每個文件系統的使用情況  -i是i節點的使用情況

2)du  顯示磁盤的使用總量 以k字節爲單位顯示文件系統磁盤空間的使用的總量

[root@localhost zhao]# df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sda2              8064304   6720040    934608  88% /
/dev/sda1               256666     18751    224663   8% /boot
none                    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.cpp
unix2dos: 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.cpp
dos2unix: 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 | more
allexport       off
braceexpand     on
emacs           on
errexit         off
errtrace        off
functrace       off
hashall         on
histexpand      on
history         on
ignoreeof       off
interactive-comments    on
keyword         off
monitor         on
noclobber       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/tty0
1908 crw-------  1 root root 4, 1 Nov 10 10:29 /dev/tty1
1909 crw-------  1 root root 4, 2 Nov 10 10:29 /dev/tty2
1910 crw-------  1 root root 4, 3 Nov 10 10:29 /dev/tty3
1911 crw-------  1 root root 4, 4 Nov 10 10:29 /dev/tty4
1912 crw-------  1 root root 4, 5 Nov 10 10:29 /dev/tty5
1913 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, <[email protected]>
#               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.sysinit

l0:0:wait:/etc/rc.d/rc 0
l1:1:wait:/etc/rc.d/rc 1
l2:2:wait:/etc/rc.d/rc 2
l3:3:wait:/etc/rc.d/rc 3
l4:4:wait:/etc/rc.d/rc 4
l5:5:wait:/etc/rc.d/rc 5
l6: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.d
total 112
drwxr-xr-x  2 root root  4096 Oct 17 12:44 init.d
-rwxr-xr-x  1 root root  2352 Mar 17  2004 rc
drwxr-xr-x  2 root root  4096 Oct 17 20:44 rc0.d
drwxr-xr-x  2 root root  4096 Oct 17 20:44 rc1.d
drwxr-xr-x  2 root root  4096 Oct 17 20:44 rc2.d
drwxr-xr-x  2 root root  4096 Oct 17 20:44 rc3.d
drwxr-xr-x  2 root root  4096 Oct 17 20:44 rc4.d
drwxr-xr-x  2 root root  4096 Oct 17 20:44 rc5.d
drwxr-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.d
total 476
lrwxrwxrwx  1 root root 21 Oct 16 07:53 K01tog-pegasus -> ../init.d/tog-pegasus
lrwxrwxrwx  1 root root 13 Oct 16 07:40 K01yum -> ../init.d/yum
lrwxrwxrwx  1 root root 24 Oct 16 07:40 K02NetworkManager -> ../init.d/NetworkManager
lrwxrwxrwx  1 root root 17 Oct 16 08:04 K02oddjobd -> ../init.d/oddjobd
lrwxrwxrwx  1 root root 14 Oct 16 08:03 K05innd -> ../init.d/innd
lrwxrwxrwx  1 root root 19 Oct 16 07:39 K05saslauthd -> ../init.d/saslauthd
lrwxrwxrwx  1 root root 19 Oct 16 07:41 K10dc_server -> ../init.d/dc_server
lrwxrwxrwx  1 root root 16 Oct 16 07:40 K10psacct -> ../init.d/psacct
lrwxrwxrwx  1 root root 17 Oct 16 08:03 K10radiusd -> ../init.d/radiusd
lrwxrwxrwx  1 root root 19 Oct 16 07:41 K12dc_client -> ../init.d/dc_client
lrwxrwxrwx  1 root root 17 Oct 16 08:02 K12FreeWnn -> ../init.d/FreeWnn
lrwxrwxrwx  1 root root 17 Oct 16 08:02 K12mailman -> ../init.d/mailman
lrwxrwxrwx  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.d
total 476
lrwxrwxrwx  1 root root 21 Oct 16 07:53 K01tog-pegasus -> ../init.d/tog-pegasus
lrwxrwxrwx  1 root root 13 Oct 16 07:40 K01yum -> ../init.d/yum
lrwxrwxrwx  1 root root 24 Oct 16 07:40 K02NetworkManager -> ../init.d/NetworkManager
lrwxrwxrwx  1 root root 17 Oct 16 08:04 K02oddjobd -> ../init.d/oddjobd
lrwxrwxrwx  1 root root 14 Oct 16 08:03 K05innd -> ../init.d/innd
lrwxrwxrwx  1 root root 19 Oct 16 07:39 K05saslauthd -> ../init.d/saslauthd
lrwxrwxrwx  1 root root 19 Oct 16 07:41 K10dc_server -> ../init.d/dc_server
lrwxrwxrwx  1 root root 16 Oct 16 07:40 K10psacct -> ../init.d/psacct
lrwxrwxrwx  1 root root 17 Oct 16 08:03 K10radiusd -> ../init.d/radiusd
lrwxrwxrwx  1 root root 19 Oct 16 07:41 K12dc_client -> ../init.d/dc_client
lrwxrwxrwx  1 root root 17 Oct 16 08:02 K12FreeWnn -> ../init.d/FreeWnn
lrwxrwxrwx  1 root root 17 Oct 16 08:02 K12mailman -> ../init.d/mailman
lrwxrwxrwx  1 root root 15 Oct 16 07:41 K15httpd -> ../init.d/httpd
lrwxrwxrwx  1 root root 15 Oct 16 08:03 K16rarpd -> ../init.d/rarpd
lrwxrwxrwx  1 root root 20 Oct 16 08:02 K20bootparamd -> ../init.d/bootparamd
lrwxrwxrwx  1 root root 24 Oct 16 08:03 K20netdump-server -> ../init.d/netdump-server
lrwxrwxrwx  1 root root 13 Oct 16 07:40 K20nfs -> ../init.d/nfs
lrwxrwxrwx  1 root root 16 Oct 16 08:02 K20rstatd -> ../init.d/rstatd
lrwxrwxrwx  1 root root 17 Oct 16 08:02 K20rusersd -> ../init.d/rusersd
lrwxrwxrwx  1 root root 15 Oct 16 08:02 K20rwhod -> ../init.d/rwhod
lrwxrwxrwx  1 root root 14 Oct 16 07:40 K24irda -> ../init.d/irda
lrwxrwxrwx  1 root root 15 Oct 16 07:41 K25squid -> ../init.d/squid
lrwxrwxrwx  1 root root 13 Oct 16 08:04 K28amd -> ../init.d/amd
lrwxrwxrwx  1 root root 22 Oct 16 07:45 K30spamassassin -> ../init.d/spamassassin
lrwxrwxrwx  1 root root 18 Oct 16 08:03 K34dhcrelay -> ../init.d/dhcrelay
lrwxrwxrwx  1 root root 19 Oct 16 08:03 K34yppasswdd -> ../init.d/yppasswdd
lrwxrwxrwx  1 root root 21 Oct 16 08:02 K35cyrus-imapd -> ../init.d/cyrus-imapd
lrwxrwxrwx  1 root root 15 Oct 16 08:03 K35dhcpd -> ../init.d/dhcpd
lrwxrwxrwx  1 root root 17 Oct 16 08:02 K35dovecot -> ../init.d/dovecot
lrwxrwxrwx  1 root root 13 Oct 16 07:41 K35smb -> ../init.d/smb
lrwxrwxrwx  1 root root 19 Oct 16 07:42 K35vncserver -> ../init.d/vncserver
lrwxrwxrwx  1 root root 17 Oct 16 08:23 K35winbind -> ../init.d/winbind
lrwxrwxrwx  1 root root 16 Oct 16 08:03 K36dhcp6s -> ../init.d/dhcp6s
lrwxrwxrwx  1 root root 14 Oct 16 07:59 K36lisa -> ../init.d/lisa
lrwxrwxrwx  1 root root 16 Oct 16 08:03 K36mysqld -> ../init.d/mysqld
lrwxrwxrwx  1 root root 20 Oct 16 08:03 K36postgresql -> ../init.d/postgresql
lrwxrwxrwx  1 root root 18 Oct 16 08:20 K45arpwatch -> ../init.d/arpwatch
lrwxrwxrwx  1 root root 15 Oct 16 08:03 K46radvd -> ../init.d/radvd
lrwxrwxrwx  1 root root 16 Oct 16 07:40 K50ibmasm -> ../init.d/ibmasm
lrwxrwxrwx  1 root root 17 Oct 16 07:40 K50netdump -> ../init.d/netdump
lrwxrwxrwx  1 root root 15 Oct 16 07:41 K50snmpd -> ../init.d/snmpd
lrwxrwxrwx  1 root root 19 Oct 16 07:41 K50snmptrapd -> ../init.d/snmptrapd
lrwxrwxrwx  1 root root 13 Oct 16 07:41 K50tux -> ../init.d/tux
lrwxrwxrwx  1 root root 16 Oct 16 08:01 K50vsftpd -> ../init.d/vsftpd
lrwxrwxrwx  1 root root 14 Oct 16 08:03 K61ldap -> ../init.d/ldap
lrwxrwxrwx  1 root root 16 Oct 16 08:03 K65kadmin -> ../init.d/kadmin
lrwxrwxrwx  1 root root 15 Oct 16 08:03 K65kprop -> ../init.d/kprop
lrwxrwxrwx  1 root root 16 Oct 16 08:03 K65krb524 -> ../init.d/krb524
lrwxrwxrwx  1 root root 17 Oct 16 08:03 K65krb5kdc -> ../init.d/krb5kdc
lrwxrwxrwx  1 root root 16 Oct 16 08:23 K73ypbind -> ../init.d/ypbind
lrwxrwxrwx  1 root root 14 Oct 16 08:23 K74nscd -> ../init.d/nscd
lrwxrwxrwx  1 root root 14 Oct 16 08:52 K74ntpd -> ../init.d/ntpd
lrwxrwxrwx  1 root root 16 Oct 16 08:03 K74ypserv -> ../init.d/ypserv
lrwxrwxrwx  1 root root 16 Oct 16 08:03 K74ypxfrd -> ../init.d/ypxfrd
lrwxrwxrwx  1 root root 14 Oct 16 08:02 K84bgpd -> ../init.d/bgpd
lrwxrwxrwx  1 root root 16 Oct 16 08:02 K84ospf6d -> ../init.d/ospf6d
lrwxrwxrwx  1 root root 15 Oct 16 08:02 K84ospfd -> ../init.d/ospfd
lrwxrwxrwx  1 root root 14 Oct 16 08:02 K84ripd -> ../init.d/ripd
lrwxrwxrwx  1 root root 16 Oct 16 08:02 K84ripngd -> ../init.d/ripngd
lrwxrwxrwx  1 root root 15 Oct 16 07:40 K85mdmpd -> ../init.d/mdmpd
lrwxrwxrwx  1 root root 15 Oct 16 08:02 K85zebra -> ../init.d/zebra
lrwxrwxrwx  1 root root 16 Oct 16 07:39 K87auditd -> ../init.d/auditd
lrwxrwxrwx  1 root root 14 Oct 17 20:44 K87ipmi -> ../init.d/ipmi
lrwxrwxrwx  1 root root 20 Oct 16 08:04 K87multipathd -> ../init.d/multipathd
lrwxrwxrwx  1 root root 15 Oct 16 08:01 K87named -> ../init.d/named
lrwxrwxrwx  1 root root 15 Oct 16 08:02 K89iscsi -> ../init.d/iscsi
lrwxrwxrwx  1 root root 18 Oct 16 07:39 K89netplugd -> ../init.d/netplugd
lrwxrwxrwx  1 root root 19 Oct 16 07:40 K90bluetooth -> ../init.d/bluetooth
lrwxrwxrwx  1 root root 18 Oct 16 07:40 K94diskdump -> ../init.d/diskdump
lrwxrwxrwx  1 root root 23 Oct 16 07:40 S00microcode_ctl -> ../init.d/microcode_ctl
lrwxrwxrwx  1 root root 17 Oct 16 08:04 S01sysstat -> ../init.d/sysstat
lrwxrwxrwx  1 root root 25 Oct 16 07:40 S04readahead_early -> ../init.d/readahead_early
lrwxrwxrwx  1 root root 15 Oct 16 07:39 S05kudzu -> ../init.d/kudzu
lrwxrwxrwx  1 root root 17 Oct 16 07:40 S05openibd -> ../init.d/openibd
lrwxrwxrwx  1 root root 18 Oct 16 07:40 S06cpuspeed -> ../init.d/cpuspeed
lrwxrwxrwx  1 root root 22 Oct 16 08:04 S08arptables_jf -> ../init.d/arptables_jf
lrwxrwxrwx  1 root root 19 Oct 16 08:02 S08ip6tables -> ../init.d/ip6tables
lrwxrwxrwx  1 root root 18 Oct 16 07:40 S08iptables -> ../init.d/iptables
lrwxrwxrwx  1 root root 14 Oct 16 07:40 S09isdn -> ../init.d/isdn
lrwxrwxrwx  1 root root 16 Oct 16 07:40 S09pcmcia -> ../init.d/pcmcia
lrwxrwxrwx  1 root root 17 Oct 16 07:39 S10network -> ../init.d/network
lrwxrwxrwx  1 root root 16 Oct 16 07:39 S12syslog -> ../init.d/syslog
lrwxrwxrwx  1 root root 20 Oct 16 07:40 S13irqbalance -> ../init.d/irqbalance
lrwxrwxrwx  1 root root 17 Oct 16 07:40 S13portmap -> ../init.d/portmap
lrwxrwxrwx  1 root root 17 Oct 16 07:40 S14nfslock -> ../init.d/nfslock
lrwxrwxrwx  1 root root 19 Oct 16 07:40 S15mdmonitor -> ../init.d/mdmonitor
lrwxrwxrwx  1 root root 19 Oct 16 07:40 S18rpcidmapd -> ../init.d/rpcidmapd
lrwxrwxrwx  1 root root 17 Oct 16 07:40 S19rpcgssd -> ../init.d/rpcgssd
lrwxrwxrwx  1 root root 14 Oct 16 08:04 S24o2cb -> ../init.d/o2cb
lrwxrwxrwx  1 root root 15 Oct 16 07:39 S25netfs -> ../init.d/netfs
lrwxrwxrwx  1 root root 15 Oct 16 08:04 S25ocfs2 -> ../init.d/ocfs2
lrwxrwxrwx  1 root root 14 Oct 16 07:40 S26apmd -> ../init.d/apmd
lrwxrwxrwx  1 root root 20 Oct 16 07:41 S26lm_sensors -> ../init.d/lm_sensors
lrwxrwxrwx  1 root root 16 Oct 16 07:40 S28autofs -> ../init.d/autofs
lrwxrwxrwx  1 root root 19 Oct 16 08:04 S29oracleasm -> ../init.d/oracleasm
lrwxrwxrwx  1 root root 17 Oct 17 12:43 S30vboxadd -> ../init.d/vboxadd
lrwxrwxrwx  1 root root 21 Oct 17 20:44 S30vboxadd-x11 -> ../init.d/vboxadd-x11
lrwxrwxrwx  1 root root 25 Oct 17 12:44 S35vboxadd-service -> ../init.d/vboxadd-service
lrwxrwxrwx  1 root root 16 Oct 16 07:40 S40smartd -> ../init.d/smartd
lrwxrwxrwx  1 root root 15 Oct 16 07:40 S44acpid -> ../init.d/acpid
lrwxrwxrwx  1 root root 14 Oct 16 07:41 S54hpoj -> ../init.d/hpoj
lrwxrwxrwx  1 root root 14 Oct 16 07:40 S55cups -> ../init.d/cups
lrwxrwxrwx  1 root root 14 Oct 16 07:40 S55sshd -> ../init.d/sshd
lrwxrwxrwx  1 root root 20 Oct 16 07:39 S56rawdevices -> ../init.d/rawdevices
lrwxrwxrwx  1 root root 16 Oct 16 07:40 S56xinetd -> ../init.d/xinetd
lrwxrwxrwx  1 root root 18 Oct 16 07:40 S80sendmail -> ../init.d/sendmail
lrwxrwxrwx  1 root root 13 Oct 16 07:40 S85gpm -> ../init.d/gpm
lrwxrwxrwx  1 root root 14 Oct 16 08:00 S87iiim -> ../init.d/iiim
lrwxrwxrwx  1 root root 15 Oct 16 08:01 S90canna -> ../init.d/canna
lrwxrwxrwx  1 root root 15 Oct 16 07:40 S90crond -> ../init.d/crond
lrwxrwxrwx  1 root root 13 Oct 16 07:41 S90xfs -> ../init.d/xfs
lrwxrwxrwx  1 root root 17 Oct 16 07:40 S95anacron -> ../init.d/anacron
lrwxrwxrwx  1 root root 13 Oct 16 07:40 S95atd -> ../init.d/atd
lrwxrwxrwx  1 root root 19 Oct 16 07:40 S96readahead -> ../init.d/readahead
lrwxrwxrwx  1 root root 20 Oct 16 07:39 S97messagebus -> ../init.d/messagebus
lrwxrwxrwx  1 root root 15 Oct 16 07:40 S97rhnsd -> ../init.d/rhnsd
lrwxrwxrwx  1 root root 28 Oct 16 07:41 S98cups-config-daemon -> ../init.d/cups-config-daemon
lrwxrwxrwx  1 root root 19 Oct 16 07:39 S98haldaemon -> ../init.d/haldaemon
lrwxrwxrwx  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 status
vsftpd is stopped
[root@localhost ~]# /etc/init.d/vsftpd start
Starting vsftpd for vsftpd:                                [  OK  ]
[root@localhost ~]# /etc/init.d/vsftpd status
vsftpd (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 --list
nfslock         0:off   1:off   2:off   3:on    4:on    5:on    6:off
postgresql      0:off   1:off   2:off   3:off   4:off   5:off   6:off
netdump         0:off   1:off   2:off   3:off   4:off   5:off   6:off
vboxadd-x11     0:off   1:off   2:off   3:on    4:off   5:on    6:off
ypbind          0:off   1:off   2:off   3:off   4:off   5:off   6:off
cpuspeed        0:off   1:on    2:on    3:on    4:on    5:on    6:off
haldaemon       0:off   1:off   2:off   3:on    4:on    5:on    6:off
nfs             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命令的功能是強制將內存中已經變化的數據塊和超級數據塊寫回硬盤中。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章