[英]'find' or 'grep' a filename to match pattern within directories and sub-directories
I need to recursively search my filesystem using a 'grep' or 'find' command to match any filename that contains the string "report". 我需要使用“ grep”或“ find”命令来递归搜索文件系统,以匹配包含字符串“ report”的任何文件名。
I attempted the command 我尝试了命令
find | grep "report[[:alnum:]]\."
and while this was close to the output I wanted, it only gave files that END in 'report.(php/tpl/whatever)' 虽然这接近我想要的输出,但只在“ report。(php / tpl / whatever)”中提供了以END结尾的文件。
What is wrong with this command, or what can I use to produce the desired output? 该命令出了什么问题,或者我可以用来产生所需的输出?
You can use the following find
command: 您可以使用以下
find
命令:
find . -name "*report*"
*
matches anything (even the empty string). *
匹配任何内容(甚至是空字符串)。 Hence, this expression matches all names being like XXXXreportYYYY
. 因此,此表达式匹配所有名称,例如
XXXXreportYYYY
。
The usage of quotes is to avoid bash expansion (try echo *
and see what happens! - How do I escape the wildcard/asterisk character in bash? may help). 使用引号是为了避免bash扩展(尝试
echo *
,看看会发生什么!- 如何在bash中转义通配符/星号?可能会有所帮助)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.