grep(global search regular expression and print out the line)
中文:全面搜索正则表达式,并按行打印输出
file_name 为在哪个文件中搜索,可以是目录。
match_pattern 是 要查找的 字符串
常用选项:
1. grep -c “5” file_name
统计各个文件中匹配的行数。
2. grep “text” -n file_name
匹配到的,该行的行号
3.grep “match_pattern” ./* -r -n
递归查找
4.grep -i “match_pattern” file_name
忽略大小写
5. grep -e “match_pattern1” -e “match_pattern2” file_name
多个搜索条件
6.grep “match_pattern” ./* -r - -include *.{php,html}
指定类型文件中查找
7.grep “match_pattern” . -r - -exclude “README”
结果中排除
8.grep “match_pattern” file_name -A 1
自动分隔 - -, 多个结果
9.grep -l “no_convert_charset” ./*
显示匹配文件名