当前目录下搜索:find . -name "*.*" | xargs grep "password=*" --color=always
备注:这个命令会输出当前目录下不存在匹配字符串的的子目录
完美的当前目录下搜索字符串命令:grep "password=*" -R -n --color=always
查找目录:find /(查找范围) -name '查找关键字' -type d
查找文件:find /(查找范围) -name 查找关键字 -print
逐层搜索文件夹以及子文件关键字:
find / -type f | egrep "\.log\$"| xargs grep -n -E -H "*assword=*" | egrep ":[ ]*[_a-zA-Z]" | sed "s:/\*.*\*/::g;s://.*::g" | egrep "*assword=*" --color=always
不同文件类型并列搜索:find / -type f | egrep "\.log\$|\.sh\$|\.xml\$" | xargs grep -i "password" --color=always
精确查找关键字:
find / -type f -name "*.log" | xargs grep -i "password" --color=always
find / -type f -name "*.log" | xargs grep -i "password" --color=auto
find / -type f | egrep "\.log\$" | xargs grep -i "password" --color=always
匹配多条件查找:可以采用or条件操作
find /var/log \( -name "rsync_yum_2016*" -o -name "rsync_yum_2017*" \) 备注:注意\(后面的空格,还有\)前面的空格
或者find /var/log -name "rsync_yum_2016*" -o -name "rsync_yum_2017*"
模糊匹配查找关键字:
1)模糊匹配文件类型 与 模糊匹配 关键字
1、【搜索慢】按字节块字符来匹配搜索
2.【搜索快】高精度 精确性搜索
2)指定文件类型 与 模糊匹配 关键字
find / -type f | egrep "*.log" |xargs grep -n -E -H '*storage*' --color=always
在多/多个不同文件类型中查找
1)指定多个个文件类型使用grep,egrep并列过滤
2)指定单个文件类型 使用grep,egrep并列过滤
find / -type f | egrep egrep "\.log\$" | xargs grep -n -E -H "*storage" | egrep ":[ ]*[_a-zA-Z]" | sed "s:/\*.*\*/::g;s://.*::g" | egrep "*storage" --color=always
本文转自yzy121403725 51CTO博客,原文链接http://blog.51cto.com/lookingdream/1896322:,如需转载请自行联系原作者