【问题标题】:Command to find N Largest files in macOS directory excluding specific directories [duplicate]在macOS目录中查找N个最大文件的命令,不包括特定目录[重复]
【发布时间】:2022-01-06 01:22:21
【问题描述】:

我想在我的项目中找到最大的文件,但不包括 .target 文件夹。 到目前为止,我找到了以下命令,但不确定如何排除 .target 文件夹。

find . -type f -exec du -h {} + | sort -hr | head -n 10

另外请分享将是什么命令,用于排除多个目录。

【问题讨论】:

  • 请告诉我为什么我的问题被否决。
  • 我刚刚查看了最近的 Apple 源代码,Apple sort 现在有 -h--human-numeric。我正在查看一个过时的手册页。
  • 不是我的反对意见,但请在询问之前搜索重复项。
  • 链接的问题没有解决问题,
  • @SahibYar 你能解释一下为什么链接的问题不能解决你的问题吗?

标签: bash macos


【解决方案1】:

只需使用-path-prune 即可排除.target 目录:

find . -path ./.target -prune -o -type f -exec du -h {} + | sort -hr | head -n 10

【讨论】:

    【解决方案2】:

    请您尝试以下方法:

    find . -type d -name .target -prune -o -type f -exec du -h {} + | sort -hr | head -n 10
    
    • -prune 是跳过前一个匹配目录的动作 条件。

    如果要排除多个目录,可以 附加目录名称,比如“exclude2”,加上-o,例如:

    find . -type d \( -name .target -o -name exclude2 \) -prune -o -type f -exec du -h {} + | sort -hr | head -n 10
    

    【讨论】:

    • find: -printf: unknown primary or operator
    • 哦,对不起。我应该知道 macOS find 不支持 -printf 选项。我已经修复了我的代码以适应您原来的 -exec 命令。
    • 好像,prune 不起作用,我仍然可以在搜索中看到 ./target 文件。
    猜你喜欢
    • 1970-01-01
    • 2017-05-07
    • 2021-11-21
    • 1970-01-01
    • 1970-01-01
    • 2011-12-08
    • 2015-02-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多