linxu find 命令 搜索字符串

当前目录下搜索:find .  -name "*.*" | xargs grep "password=*" --color=always  

备注:这个命令会输出当前目录下不存在匹配字符串的的子目录

完美的当前目录下搜索字符串命令:grep "password=*" -R -n --color=always


全量目录搜索:find  / -name "*.*" | xargs grep -i "password=*" |grep -v "password=*" --color=always  
逐层搜索文件夹以及子文件关键字

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、【搜索慢】按字节块字符来匹配搜索
find / -type f -name "*.*"  | xargs grep -R -i -E '*@storage*|*assword*'  --color=always


2.【搜索快】高精度 精确性搜索
find / -type f | egrep "\.log\$" | xargs grep -R -i -E '*@storage*|*assword*'  --color=always
find / -type f | egrep "\.log\$|\.sh\$" | xargs grep -R -i -E  "*@storage*|*assword*" --color=always

2)指定文件类型  与  模糊匹配 关键字
find / -type f -name "*.log"  | xargs grep -n -E -H "*@storage*" --color=always
find / -type f | egrep "\.log\$" | xargs grep -R -i -E '*@storage*'  --color=always
find / -type f | egrep "*.log" |xargs grep -n -E -H  '*storage*'  --color=always
find / -type f | egrep "\.log\$"| xargs grep -n -E -H "*@storage*" | egrep ":[ ]*[_a-zA-Z]" | sed "s:/\*.*\*/::g;s://.*::g" | egrep "*@storage*|*assword*" --color=always

目录下搜索:grep -niR 'Admin@storage' /  --color=always
cat *.* | grep -n -E -H '*@storage*|*assword*'  --color=always
cat *.* | grep -R -i -E '*@storage|*assword' --color=always

在多/多个不同文件类型中查找
1)指定多个个文件类型使用grep,egrep并列过滤
find / -type f | egrep "\.sql\$|\.log\$|\.cfg\$|\.cpp\$|\.h\$|\.hpp\$|\.htm\$|\.html\$|\.inc\$|\.Java\$|\.js\$|\.jsp\$|\.pl\$|\.properties\$|\.sh\$|\.xml\$"| xargs grep -n -E -H "pass|password" | egrep ":[ ]*[_a-zA-Z]" | sed "s:/\*.*\*/::g;s://.*::g" | egrep "pass|password"  >  check_Security.log 

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


本文出自 “梦想照进现实” 博客,请务必保留此出处http://lookingdream.blog.51cto.com/5177800/1896322


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章