【问题标题】:How to combine tree and wc -l?如何结合树和 wc -l?
【发布时间】:2018-11-20 23:45:12
【问题描述】:

我有带有子文件夹的文件夹base_dir,每个子文件夹都包含.jpg图像,我想要类似于tree -L 1 base_dir的输出,但是子文件夹名称旁边有多个jpg图像,可以吗?

【问题讨论】:

    标签: linux bash tree ls wc


    【解决方案1】:

    这将输出类似的东西:

    find  base_dir -mindepth 1 -maxdepth 1 -type d -print0 | 
    xargs -0 -n1 sh -c 'echo "$1 $(find "$1" -name "*.jpg" | wc -l)"' --
    

    对于 base_dir 中的每个目录,输出目录名称和名为 *.jpg 的文件的数量。示例输出:

    base_dir/b 2
    base_dir/a 1
    base_dir/d 3
    base_dir/c 0
    

    【讨论】:

      猜你喜欢
      • 2015-03-30
      • 2023-03-03
      • 2020-05-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-26
      • 1970-01-01
      相关资源
      最近更新 更多