找到包含特定文本的路径

时间:2013-08-06 17:16:21

标签: linux unix

如何查找包含字符串的所有路径" tomcat"从特定目录? 即我想找到任何包含tomcat1,tomcat2,tomcat3等的东西?

感谢。

5 个答案:

答案 0 :(得分:5)

尝试

find . -iname tomcat\*

用你的目录替换点来搜索,或者 cd 替换你要搜索的目录。

如果您只想搜索目录名称,请尝试

find . -type d -iname tomcat\*

答案 1 :(得分:2)

如果没有上下文,这里的其他答案可能会有些混乱。简短的回答是查看find的手册页,但我可以在这里添加一些摘要。基本上你想要:

find <starting path> -iname "tomcat*"

如果您希望-iname区分大小写,可以将其更改为-name。如果您只想在当前目录中搜索并降低,则应使用.作为起始目录。如果要搜索整个文件系统,请使用/。如果你想使用tomcast有任何文件名,即使它稍后在文件中,也要使用"*tomcat*"。您只需要找出最适合您搜索的内容。

答案 2 :(得分:1)

使用find:

find / -name "tomcat*"

答案 3 :(得分:1)

使用Linux find(GNU findutils)4.7尝试-wholename测试:

find . -wholename */tomcat*

find . -type d -wholename */tomcat*

答案 4 :(得分:-1)

尝试grep

grep -r "tomcat" dir