选项
-E 使用正则等同于 egrep-c 统计匹配出的文本行数-o 只显示匹配到的结果-v 对输出结果取反-n 显示匹配结果所在行数-i 匹配时不考虑大小写-r -R 递归匹配-e 指定匹配多个模式-f 从文件中读取grep需要筛选的选项
# -R 递归查询
# -n 查询时显示行号
root@jason:/etc# grep -R -n "test_function()" .
./profile:2:test_function()
# 以上命令等价于
root@jason:/etc# find . -type f | xargs grep "test_function()"
./profile:test_function()
# 使用 -e 选项,定义两个匹配项
root@jason:~# find . -type f | xargs grep -e "chen" -e "chendi"
# 读取 1.tt 文件内容进行匹配
root@jason:~# find . -type f | xargs grep -f 1.tt
# 使用 --include 选项在目录中递归搜索所有的 .c 和 .cpp 文件
root@jason:/etc# grep "main()" . -r --include *.{c,cpp}
--exculde-dir 可以排除目录
--exculde 可以排除文件