找到-name" * XYZ" -o -name" * ABC&QUOT。 -exec来执行所有找到的文件,指定不只是过去的后缀 [英] find -name "*.xyz" -o -name "*.abc" -exec to Execute on all found files, not just the last suffix specified

查看:111
本文介绍了找到-name" * XYZ" -o -name" * ABC&QUOT。 -exec来执行所有找到的文件,指定不只是过去的后缀的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图运行

find ./ -name "*.xyz" -o -name "*.abc" -exec cp {} /path/i/want/to/copy/to

在现实中,它的扩展名的名单更大,但我不知道,在这个例子中的问题。基本上,我想找到复制到其他所有的/路径/我/想/到/复制/到。然而,它似乎只在列表中执行的最后一个测试-name

In reality it's a larger list of name extensions but I don't know that matters for this example. Basically I'd like to copy all those found to another /path/i/want/to/copy/to. However it seems to only be executing the last -name test in the list.

如果我删除-exec部分我希望可以找到文件的所有变化都打印出来。

If I remove the -exec portion all the variations of files I expect to be found are printed out.

我如何得到它通过发现-exec文件充分补充?

How do I get it to pass the full complement of files found to -exec?

推荐答案

找到的工作原理是评估前pressions你给它,直到它可以确定真值整个前pression的(true或false)。在你的情况,你基本上执行以下操作,因为默认情况下它ANDS除权pressions在一起。

find works by evaluating the expressions you give it until it can determine the truth value (true or false) of the entire expression. In your case, you're essentially doing the following, since by default it ANDs the expressions together.

-name "*.xyz" OR ( -name "*.abc" AND -exec ... )

答曰手册页:

GNU find搜索
         通过评估在每个给定文件名根的目录树
         给定的前pression从左到右,根据precedence的规则(见节算),直到结果是已知的(左
         手侧为假并操作,或真),在该点
         找到下一个文件名的动作。

GNU find searches the directory tree rooted at each given file name by evaluating the given expression from left to right, according to the rules of precedence (see section OPERATORS), until the outcome is known (the left hand side is false for and operations, true for or), at which point find moves on to the next file name.

这意味着,如果名称匹配 * XYZ ,它甚至不会尝试检查后 -name 测试或 -exec ,因为它已经成为事实。

That means that if the name matches *.xyz, it won't even try to check the latter -name test or -exec, since it's already true.

您想要做的是执行precedence,您可以用括号做。烦人的,你还需要使用反斜杠逃脱他们的外壳:

What you want to do is enforce precedence, which you can do with parentheses. Annoyingly, you also need to use backslashes to escape them on the shell:

find ./ \( -name "*.xyz" -o -name "*.abc" \) -exec cp {} /path/i/want/to/copy/to \;

这篇关于找到-name" * XYZ" -o -name" * ABC&QUOT。 -exec来执行所有找到的文件,指定不只是过去的后缀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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