【问题标题】:Exclude a subpath in find command [duplicate]在查找命令中排除子路径[重复]
【发布时间】:2015-12-16 02:25:13
【问题描述】:

我有以下find 命令:

find /mnt/F_11 -type f \( -iname '*.xls' -o -iname '*.xlsx' /)

我如何在/mnt/F_11 中找到所有项目,但在/mnt/f_11/DONOTENTER/ 中找不到?

换句话说,我希望它搜索:

YES /mnt/F_11
YES /mnt/F_11/somepath/
YES /mnt/F_11/somepath/other/
NO  /mtn/F_11/DONOTENTER/

【问题讨论】:

    标签: linux unix find


    【解决方案1】:

    使用-prune 避免递归你不想遵循的分支。

    find /mnt/F_11 -name DONOTENTER -prune -o \
         -type f \( -iname '*.xls' -o -iname '*.xlsx' \) -print
    

    注意最后的显式-print——这很重要,否则隐式打印操作会覆盖两个分支。

    【讨论】:

    • 会比-not -path /mnt/F_11/DONOTENTER* 快​​吗?
    • 是的,因为-prune 停止沿路径递归,而给出的其他方法将测试该子树中的内容。
    猜你喜欢
    • 2016-11-03
    • 2015-06-27
    • 2021-01-02
    • 1970-01-01
    • 2019-10-08
    • 2012-04-07
    • 2012-09-21
    • 2014-03-08
    • 1970-01-01
    相关资源
    最近更新 更多