【问题标题】:Omit a directory when searching with find [duplicate]使用 find [重复] 搜索时省略目录
【发布时间】:2022-01-02 04:17:21
【问题描述】:

使用以下方法搜索整个系统:

find / -type f -size +100M -exec ls -lh {} \; | awk '{ print $9 "|| Size : " $5 }'

如何省略目录?我看到 -prune -o,但我不确定如何格式化选项。

【问题讨论】:

  • Stack Overflow 用于编程问题,而不是关于使用或配置 Unix 及其实用程序的问题。 Unix & LinuxSuper User 将是解决此类问题的更好地方。
  • find / -type d -name 'directory_to_omit' -prune -o -type f ...
  • Don't use ls in scripts. 如果你真的在Linux上,你想使用find-printf谓词来打印出你想要的字段。

标签: linux bash shell search find


【解决方案1】:

来自man

要忽略整个目录树,请使用 -prune 而不是 而不是检查树中的每个文件。例如,要跳过 目录src/emacs 及其下的所有文件和目录, 并打印找到的其他文件的名称,执行类似的操作 这: find . -path ./src/emacs -prune -o -print 请注意,模式匹配测试适用于整个文件名, 从命令行命名的起点之一开始。

【讨论】:

    【解决方案2】:
    find / -path /path/to/ommit -prune -o -type f -size +100M -exec ...
    #      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-11-27
      • 2017-09-01
      • 2012-05-12
      • 1970-01-01
      • 2018-10-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多