#############################
# # # # # Unit6.shell script Command # #
#############################
########## #1. diff###########
diff File File1 # #比较两个文件的不同
-C # #显示周围的行
-U # #按照统一格式输出生成补丁
-R # #比较两个目录中文件的不同
Patch File File.patch # #打补丁
-B # #备份原文件
######## #2. grep##########
grep keyword
Grep-i # #忽略大小写
-N # #显示关键字在其文件所在的行号
-C # #显示过滤结果的个数
-V # #反向过滤 (that is, rows that do not contain the keyword)
-e "keyword 1| keyword 2" # #过滤多个关键字
-R Directory # #在目录中查找含有关键字的文件 (recursive search, starting from a named directory)
Note: ^ keyword # #以关键字开头
Keyword $ # #以关键字结尾
Eg.grep Root-r/etc/-N # #递归式搜索/etc/with root directories and files, and displays the root's line number in the file
######## #3. cut##########
Cut # #截取字符
cut-d Delimiter # #指定分隔符
Cut-f 1,7 # #显示指定的列
Cut-c 1-4 # #显示指定的字符
eg. show only IP address information in the Ifconfig
[Email protected]/]# ifconfig eth0 | grep inet |grep-v inet6| Cut-d ""-F 10
inet 172.25.254.119
[Email protected]/]# ifconfig eth0 | grep inet |grep-v inet6| Awk-f "" ' {print $1,$2} '
inet 172.25.254.119
# #awk的-F indicates the specified delimiter
####### #4. Sort sorted ########
Sort # #默认只按第一个字符排序
-N # #纯数字排序
-U # #去除冗余
|UNIQ-C # #去除冗余并统计冗余的个数
-T # #指定分隔符
-K # #指定列
eg
[Email protected] mnt]# sort-t ":"-K 2-n file
A:1
A:2
A:2
A:3
A:4
A:5
A:5
A:6
A:6
A:7
####### #5. uniq#######
Sort file |uniq-c # #去冗余并统计冗余次数
-D # #显示冗余行
-U # #显示唯一行
###### #6. tr#######
###### #7. sed######
Sed ' s/original character/replacement character/g ' file # #替换文件中的字符
Sed-e ' Strategy 1 '-e ' policy 2 ' File # #执行多个策略 (This strategy is ' s/original character/replacement character/g ')
Sed-i File # #把转换后的内容输出到指定文件
Sed ' 3,5s/original character/replacement character/g ' File # #把3-5 line replacement
sed xd file # #屏蔽指定行 (eg.sed 5d passwd)
sed xp file # #复制指定行 (eg.sed 5p passwd)
Sed-n XP File # #只显示指定行 (eg.sed-n 5p passwd)
Note: When you want to perform multiple specified rows, the command format is Sed-ne Xp-ne XP
Eg:sed-ne 5p-ne 7p File
######## #8. awk##########
Western Open Source Study Note book2-"unit 6"