目前目錄下搜尋: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:,如需轉載請自行聯系原作者