linxu find 命令 搜索字符串

简介:

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

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

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

查找目录:find /(查找范围) -name '查找关键字' -type d
查找文件:find /(查找范围) -name 查找关键字 -print

find . -type f -size +500M

-type 指定查找类型为文件  -size 指定文件大小 +表示大于500M

逐层搜索文件夹以及子文件关键字

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





     本文转自yzy121403725 51CTO博客,原文链接http://blog.51cto.com/lookingdream/1896322:,如需转载请自行联系原作者



相关文章
|
2月前
|
Unix Linux
`grep`命令进行文本搜索并忽略大小写
`grep`命令进行文本搜索并忽略大小写
37 2
|
2月前
grep的反向搜索
grep的反向搜索
17 3
|
2月前
|
Shell Linux C语言
【Shell 命令集合 文档编辑 】Linux 递归搜索指定字符串 rgrep命令使用指南
【Shell 命令集合 文档编辑 】Linux 递归搜索指定字符串 rgrep命令使用指南
20 0
|
7月前
|
Linux
Linux find 文件目录搜索工具
前言 find是一个在Linux系统中非常强大和灵活的文件搜索工具。它用于在文件系统中查找文件和目录,并可以执行各种搜索任务,可帮助系统管理员和用户有效地管理文件系统。
50 0
|
2月前
|
Unix Linux
`grep`命令搜索单个字符串
`grep`命令搜索单个字符串
24 2
|
2月前
|
Linux
`grep`命令搜索多个文件中的特定模式
`grep`命令搜索多个文件中的特定模式
29 2
|
3月前
|
Shell
grep 搜索当前文件夹下的所有子文件中的文件是否包含8888字符串的命令
要在当前文件夹及其所有子文件夹中的文件中搜索包含字符串 "8888" 的文件,你可以使用 grep 命令结合 -r 或 -R 选项(表示递归搜索)。这里是具体的命令: bash grep -r "8888" . 其中: -r 或 -R:递归搜索。 "8888":你要搜索的字符串。 .:表示当前目录。 这个命令会列出所有包含字符串 "8888" 的文件的名称以及匹配的行。如果你只想看到文件名,而不看具体的匹配行,可以加上 -l 选项: bash grep -rl "8888" . 这样,命令只会输出包含字符串 "8888" 的文件名。
|
3月前
|
Linux PHP 开发工具
Linux查找含有某字符串文件并批量替换
Linux查找含有某字符串文件并批量替换
|
8月前
|
Unix Linux
如何在 Linux 中使用 Grep 和正则表达式进行文本搜索?
如何在 Linux 中使用 Grep 和正则表达式进行文本搜索?
199 5
|
9月前
|
机器学习/深度学习 Linux
Linux强大的文本搜索命令:egrep
Linux强大的文本搜索命令:egrep
135 0