【问题标题】:Exclude sub directories from find: why is -not -path not working?从查找中排除子目录:为什么 -not -path 不起作用?
【发布时间】:2014-10-01 00:51:27
【问题描述】:
java -jar ~/Downloads/simian-2.3.35/bin/simian-2.3.35.jar files $(find ~/App/Classes/ -type f -name "*.m"  -not -path  "Lib/excludethisdir/*")

我正在尝试运行 simian 并将文件参数传递给它,但排除目录不起作用。 Lib 目录包含在 Classes 中

谁能指出它为什么不起作用(命令运行,但不排除)

【问题讨论】:

  • 也不确定 simian 到底是什么,但是这将在包含空格的文件上失败,并且如果 find 返回很多文件,则可以运行超过 ARG_MAX
  • 嗨 BroSlow,simian 是一个用 Java 编写的复制粘贴检测器。这些文件没有空格。当命令运行时,它似乎没有击中ARG_MAX - 678 个文件。

标签: macos shell terminal find


【解决方案1】:

你嵌套的 find 命令应该是:

find ~/App/Classes/ -type f -name "*.m"  -not -path "./Lib/excludethisdir/*"

即在排除路径前添加./

甚至更好:

find ~/App/Classes/ -path "./Lib/excludethisdir/*" -prune -o -type f -name "*.m" -print

【讨论】:

  • 值得注意的是-prune 更快,即find ~/App/Classes/ -path "./Lib/excludethisdir" -prune -o -type f -name "*.m" -print 之类的东西比每次检查都快。
  • 感谢@BroSlow:我将其添加到我的答案中。
  • 嗨,anubhava,这对我仍然不起作用。它可能与我从哪里运行命令有关吗?我运行这个命令时在“App”目录下,“Lib”是“Classes”的子目录
  • 是的,你需要给出排除的完整路径。所以给"./classes/Lib/excludethisdir/*
猜你喜欢
  • 2018-03-26
  • 2018-09-28
  • 1970-01-01
  • 2021-06-21
  • 2013-05-29
  • 2021-11-22
  • 2013-05-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多