从查找中排除目录。命令 [英] Exclude directory from find . command

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

问题描述

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



这里是我们使用的查找代码。

$ p $ 用于$(find。-name'* .js')中的文件。做java -jar config / yuicompressor-2.4.2.jar - 类型js $文件-o $文件;完成


解决方案

使用prune开关,例如如果你想要排除 misc 目录,只需将 -path ./misc -prune -o 添加到find命令中:

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

这是一个例如有多个目录:

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

这里我们排除了dir1,dir2和dir3,因为在中找到表达式,它是一个动作,作用于条件 - 路径dir1 -o -path dir2 -o -path dir3 (如果dir1或dir2或dir3),与键入-d 。进一步的行动是 -o print ,只是打印。

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

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

解决方案

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

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. Further action is -o print, just print.

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

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