代码之家  ›  专栏  ›  技术社区  ›  Snowcrash

对于tree命令,-P开关似乎不起作用

  •  1
  • Snowcrash  · 技术社区  · 7 年前

    我正在使用:

    tree . --prune --matchdirs -P dir-name

    哪些匹配:

    /目录/目录名

    但是

    tree . --prune --matchdirs -P dir-*

    不匹配。

    这种模式有问题吗?

    我指的是 https://manned.org/tree/11711706 但是使用MacOSX。

    2 回复  |  直到 7 年前
        1
  •  2
  •   John Manko    7 年前

    你试过用单引号把图案括起来吗?

    tree . --prune --matchdirs -P 'dir-*'

        2
  •  0
  •   Community Mohan Dere    6 年前

    即使在使用时,也不能忽略不匹配的目录 --prune -P 在文件夹和 --matchdirs 选项。

    从1.8.0文档:

    --匹配目录:

    目录内容的匹配被禁用 . 如果使用--prune选项,则不会修剪与模式匹配的空文件夹。

    所以呢 ,区别在于 只有所有匹配的目录才会显示其所有内容 .

    --

    tree
    .
    ├── abc
    │   ├── foo.txt
    │   └── xyz.txt
    ├── abc.txt
    ├── xyz
    │   ├── abc.txt
    │   └── bar.txt
    └── xyz.txt
    
    2 directories, 6 files
    

    Matchdirs和prune,仍然显示不匹配的文件夹。

    tree -P "x*" --matchdirs --prune
    .
    ├── abc
    │   └── xyz.txt
    ├── xyz
    │   ├── abc.txt
    │   └── bar.txt
    └── xyz.txt
    
    2 directories, 4 files
    

    即使我曾经 --修剪 仍显示不匹配的文件夹。也就是说,因为文件夹中的文件与 -第

    结论:

    -P不表示只包含与字符串匹配的文件夹名称。

    推荐文章