【问题标题】:find how to exclude path找到如何排除路径
【发布时间】:2019-11-01 20:15:41
【问题描述】:

我想查找 /usr/ 中的所有文件,但不在 /usr/share 中

来自这个帖子Exclude a sub-directory using find 我试过了:

find /usr -type f -not -path /usr/share -print

-> 从 /usr/share 打印文件

来自这个帖子How to exclude a directory in find . command 我试过了:

find /usr -path /usr/share -prune -print 

->尽管 /usr/bin 中有文件,但什么也不输出

我也试过了:

find /usr -path ! /usr/share -type f -print 

-> 输出错误

【问题讨论】:

    标签: bash find


    【解决方案1】:

    删除-print 并否定-path ... -prune

    find /usr ! \( -path '/usr/share' -prune \) -type f
    

    【讨论】:

      【解决方案2】:

      默认情况下,布尔值and 用于连接运算符和初级。所以find /usr -path /usr/share -prune -print 等同于find /usr -path /usr/share -prune -a -print。但是你想打印没有修剪的东西。所以使用:

      find /usr -path /usr/share -prune -o -print
      

      如果您想将搜索限制为常规文件:

      find /usr -path /usr/share -prune -o -type f -print
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-03-10
        • 2014-01-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-03-24
        相关资源
        最近更新 更多