小编典典

如何在 find 中排除目录,命令

linux

我正在尝试find为所有 JavaScript 文件运行命令,但如何排除特定目录?

这是find我们正在使用的代码。

for file in $(find . -name '*.js')
do 
  java -jar config/yuicompressor-2.4.2.jar --type js $file -o $file
done

阅读 276

收藏
2022-02-16

共2个答案

小编典典

如果-prune对您不起作用,这将:

find -name "*.js" -not -path "./directory/*"

警告:需要遍历所有不需要的目录。

2022-02-16
小编典典

使用-prune初级。例如,如果您想排除./misc

find . -path ./misc -prune -o -name '*.txt' -print

排除多个目录,或在括号之间。

find . -type d \( -path ./dir1 -o -path ./dir2 -o -path ./dir3 \) -prune -o -name '*.txt' -print

并且,要在任何级别排除具有特定名称的目录,请使用-name主目录而不是-path.

find . -type d -name node_modules -prune -o -name '*.json' -print
2022-02-16