简体   繁体   English

“查找”或“ grep”文件名以匹配目录和子目录中的模式

[英]'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.

相关问题 在目录和子目录中搜索文件,并编辑这些文件中的特定行 - Searching for files in a directory and sub-directories and editing specific lines within those files 在目录和子目录中搜索/查找所有 .mkv - Search/Find All .mkv in directories and sub directories 使用ack(或类似的东西),如何排除子目录 - With ack (or something similar), how do I exclude sub-directories Python 2.7 脚本 - 在目录和子目录中的所有文件中搜索字符串 - Python 2.7 Script - Searching for a String in all files in Directories and Sub-Directories 搜索目录中的所有子目录 - Searching through all sub directories within a directory PowerShell - 无法通过子目录递归搜索 [LIKE] 文件名 - PowerShell - Unable to Search for [LIKE] File Names recursively through sub-directories 递归搜索子目录,忽略目录PHP - Recursively search sub directories, ignore directories PHP 如何从目录和子目录中找到包含在多个文件中的函数? - How can i find a function which is included in multiple files from directories and sub directories? PowerShell,在特定目录中搜​​索特定文件名 - PowerShell, search specific directories for specific filename 任何 javascript 方法,如 php “glob” 来获取与指定模式匹配的文件名或目录? - Any javascript method like php “glob” to get filenames or directories that match the specified pattern?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM