1.diff比較兩個文件的不同
diff -u file file.new >file.path##生成補丁文件
yum install patch -y##安裝打補丁工具
patch -b file file.path##給老軟件打補丁,清且對老軟件進行備份
2.grep##過濾字符
-i##或略大小寫
-n##顯示結果所在行的行號
-c##結果個數
-v##反向過濾
-r 關鍵字目錄##在目錄中過濾還有關鍵字的文件
-E "關鍵字1|關鍵字2|....."##過濾多個關鍵字
3.sort##排序
-n##純數字
-r##倒序
-u##去掉重複行
-t##指定分隔符
-k##指定排序的列
4.uniq##處理重複行
-c##統計重複行的個數
-u##顯示唯一的行
-d##顯示重複行
5.tr##轉換字符大小寫
tr 'a-z' 'A-Z'<file##把file中所有小寫字符轉換成大寫
6.sed(-i 表示將更改同步到原文件)##控制流輸出
sed 's/nologin/westos/g' passwd ##替換輸出中的nologin爲westos
sed '1,5s/nologin/westos/g' passwd ##替換輸出中1-5行的nologin爲wesots
sed '/games/,/nobody/s/nologin/westos/g' passwd##替換輸出中的games字符到nobody字符之間的nologin爲westos
sed -e 's/nologin/westos/g' -e 's/sbin/lee/g' passwd##多條替換策略用-e連接
sed 3d passwd##不顯示文件中的第三行
sed 3,7d file##不顯示文件中的3-7行
sed 3,7p file ##重複顯示文件中的3-7行
sed -n 3,7p file ##只顯示文件中的3-7行
[root@westos mnt]# cat rule ##規則文件內容
s/nologin/westos/g
s/sbin/lee/g
[root@westos mnt]# sed -f rule file ##使用規則文件更改輸出
1root:x:0:0:root:/root:/bin/bash
2bin:x:1:1:bin:/bin:/lee/westos
3daemon:x:2:2:daemon:/lee:/lee/westos
4adm:x:3:4:adm:/var/adm:/lee/westos