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


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