unit6


1.diff,patch命令

  diff -c file file1                      ##查看上下文周围的行

Test2 unit6_Test

diff -u file file1 > file.path             ##补丁

yum install patch -y                      ##安装打补丁工具

Test2 unit6_unit6_02

patch -b file file.path                   ##备份file

Test2 unit6_unit6_03

  patch file file.path                          ##给file打补丁

Test2 unit6_Test_04

Test2 unit6_unit6_05

  2.grep命令

grep root passwd                                ##查找字符root

Test2 unit6_Test_06

grep -i test passwd                             ##查找忽略大小写

Test2 unit6_Test_07 


grep -n test passwd                            

Test2 unit6_Test_08

grep -c test passwd                           

Test2 unit6_unit6_09

grep -v -i test passwd                         ##反向查找

Test2 unit6_Test_10

grep -E “root|test” passwd               ##查找“”中字符

Test2 unit6_unit6_11

grep -i test -r /mnt/                     ##递归查找目录里的字符

Test2 unit6_unit6_12

grep ^root passwd                        ##查找在行首的字符

grep root$ passwd                        ##查找在行尾的字符

Test2 unit6_unit6_13

grep -i test passwd | grep -v -i -E "^tset|test$"  ##查找在不在行首行尾的字符


Test2 unit6_unit6_14

3.cut 命令

cut -d : -f 1 passwd                             ##-d指定分隔符 -f指定字段

Test2 unit6_Test_15

cut -c 2-5 passwd                                ##-c 指定文本列

Test2 unit6_Test_16


4.sort,uniq命令

sort -n test                                     ##按升序排列

Test2 unit6_Test_17

sort -run test                                    ##按降序排列

Test2 unit6_Test_18


sort -t : k 1 -run test                          ##-t指定分隔符 k指定字段

Test2 unit6_Test_19

sort -rn test | uniq -u                             ##显示唯一行

Test2 unit6_Test_20

sort -rn test | uniq -d                            ##显示重复行

Test2 unit6_Test_21

    

sort -rn test | uniq -c                            ##统计行数

Test2 unit6_unit6_22

5.tr 命令

tr 'a-z''A-Z'  <file                        ##小写大写

tr 'A-Z' 'a-z' <file                               ##大写变小写

Test2 unit6_unit6_23

 6.sed 命令

sed ‘s/root/westos/g’ passwd                                 ##将文件内root换成westos

Test2 unit6_Test_24

 

sed ‘s/root/westos/g’-i passwd                                  ##将结果输入到文件

Test2 unit6_unit6_25

sed -e‘s/root/westos/g’ -e 's/nologin/west/g' passwd  ##同时转换两个字符

Test2 unit6_Test_26

sed 5d westos                                            ##隐藏第5行

Test2 unit6_unit6_27 

sed 5p westos                                         ##重复第5行

Test2 unit6_Test_28

sed ‘3,5s/root/westos/g’ passwd                    ##把3-5行的root换为westos


Test2 unit6_Test_29

sed -n 5p westos   ##单独列出第五行

Test2 unit6_Test_30

sed -ne 2p -ne 4p westos   ##列出第二行和第四行

Test2 unit6_unit6_31