【问题标题】:How can I use tree to find a specific file如何使用树查找特定文件
【发布时间】:2017-07-14 04:38:50
【问题描述】:

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

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

树 -P '_tree_file_' .

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

谢谢!

阿基

【问题讨论】:

  • 请澄清:您是否想要名称包含_test_file_ 的文件(在这种情况下,使用find)?还是要查找内容包含字符_test_file_ 的文件(在这种情况下,使用grep -r)?
  • 已经在上面编辑过-你是对的-使用 find 是最好的解决方案

标签: bash shell unix directory


【解决方案1】:

来自手册页:

-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_*'

【讨论】:

    猜你喜欢
    • 2017-12-31
    • 1970-01-01
    • 1970-01-01
    • 2021-02-08
    • 2016-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-07
    相关资源
    最近更新 更多