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

查看:2213
本文介绍了如何在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目录,只需在您的find命令中添加-path ./misc -prune -o:

Use the -prune switch. For example, if you want to exclude the misc directory just add a -path ./misc -prune -o to your find command:

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

以下是具有多个目录的示例:

Here is an example with multiple directories:

find . -type d \( -path dir1 -o -path dir2 -o -path dir3 \) -prune -o -print

这里我们排除了 dir1 dir2 dir3 ,因为在find表达式中,这是一个作用于条件(如果 dir1 dir2 dir3 ),则与type -d进行与"运算.

Here we exclude dir1, dir2 and dir3, since in find expressions it is an action that acts on the criteria -path dir1 -o -path dir2 -o -path dir3 (if dir1 or dir2 or dir3), ANDed with type -d.

进一步的操作是-o print,只需打印即可.

Further action is -o print, just print.

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

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