1.非递归搜索包含指定字符串的文件

grep 查找在当前目录下,包含mirrors.aliyuncs.com字符串的文件

grep mirrors.aliyuncs.com ./*

查找结果:

 

2.递归地搜索包含指定字符串的文件

grep -R mirrors.aliyuncs.com ./*

 

 

3.搜索所有包含特定单词的文件

比如grep查找aliyuncs

grep aliyuncs ./*  则所有包含这个字符串的内容都会显示,不管是aliyuncstest.com   ,还是abcaliyunc  都会被找到。

但是,如果是加上-w,则必须单词只能是aliyuncs,比如aliyuncsb.com,ialiyuncs多一个字都不行

 

grep -w aliyuncs ./*

 

 

4.大小写不敏感的搜索

通过使用 grep 的 -i 选项即可。

 

5.搜索时包含/排除指定文件(文件夹--exclude-dir

包含  grep  --include=\*.conf bash /etc/*  

 排除   grep  --exclude=\*.conf bash /etc/*

 

 

Logo

更多推荐