如何使用树来查找特定文件

时间:2017-07-14 04:38:51

标签: bash shell unix directory

我想在复杂的目录结构中找到与特定正则表达式匹配的文件列表。例如,文件名中包含_test_file_的文件。

我尝试了以下命令但收效甚微:

tree -P' _tree_file _ '。

这将返回0找到的文件。似乎有解决方案使用find,但我想尽可能使用树。

谢谢!

1 个答案:

答案 0 :(得分:2)

从手册页:

-P pattern
      List  only  those files that match the wild-card pattern.  Note:
      you must use the -a option to also consider those  files  begin‐
      ning  with a dot `.' for matching.  Valid wildcard operators are
      `*' (any zero or more characters), `?' (any  single  character),
      `[...]'  (any single character listed between brackets (optional
      - (dash) for character  range  may  be  used:  ex:  [A-Z]),  and
      `[^...]'  (any  single character not listed in brackets) and `|'
      separates alternate patterns.

命令tree -P '_tree_file_'的输出将是名称与“_tree_file _”完全匹配的文件。

您可以尝试为您的请求使用通配符:

$ tree -P '*_tree_file_*'