如何在 find 中排除目录.命令 [英] How to exclude a directory in find . command

查看:58
本文介绍了如何在 find 中排除目录.命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to run a find command for all JavaScript files, but how do I exclude a specific directory?

这是我们使用的 find 代码.

Here is the find code we're using.

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

推荐答案

使用 -prune 主要.例如,如果要排除 ./misc:

Use the -prune primary. For example, if you want to exclude ./misc:

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

要排除多个目录,请在括号之间进行 OR.

To exclude multiple directories, OR them between parentheses.

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

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

And, to exclude directories with a specific name at any level, use the -name primary instead of -path.

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

这篇关于如何在 find 中排除目录.命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆