Unix find命令:多个-o和exec参数无法同时使用

5
当我运行以下命令时,尽管find命令显示结果,但没有文件被移动。
find "/Users/Vino/Media/test" -type f -size +100M \
  -name *.mkv -o -name *.mp4 -o -name *.avi \
  -exec mv {} /Users/Vino/Media/ \;

但是,当我删除 .avi 和 .mp4 的 or 运算符时,它会按照预期执行。

find "/Users/Vino/Media/test" -type f -size +100M \
  -name *.mkv -exec mv {} /Users/Vino/Media/ \;

我有点困惑,因为这是一个相当简单的命令,我曾经在 OS X 10.6 下使用过。现在我正在使用 OS X 10.9。


1
如果你将 -name *.mkv -o -name *.mp4 -o -name *.avi 改为 \( -name *.mkv -o -name *.mp4 -o -name *.avi \),会发生什么? - Biffen
@Biffen 那个可以。谢谢。 - Vino
Vino,欢迎来到StackOverflow!@Biffen如果您将您的评论发布为答案,Vino可以接受它。 - Anthony Geoghegan
1个回答

5

将我的评论转化为答案。

你需要让find清楚哪些是-o的运算对象。你可以通过使用()进行分组来实现:

find "/Users/Vino/Media/test" -type f -size +100M \
  \( -name *.mkv -o -name *.mp4 -o -name *.avi \) \
  -exec mv {} /Users/Vino/Media/ \;

来自man页面

( expr )
       Force precedence.  Since parentheses are special to  the  shell,
       you  will  normally need to quote them.  Many of the examples in
       this manual page use backslashes  for  this  purpose:  `\(...\)'
       instead of `(...)'.

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接