在终端中,如何在不同文件上多次重复执行命令?


13

在终端中,我想使用ffmpeg2theora将某个目录中的所有.MOV文件转换为.ogv文件。但是,以下操作无效:

ffmpeg2theora *.MOV

有没有一种好方法可以在不同文件上多次重复执行命令?

谢谢!

Answers:


20

如果使用默认外壳程序(bash),则可以使用以下命令:

for file in *.MOV; do ffmpeg2theora "$file"; done

5
这更可能在不使用斜线的情况下起作用:for file in *.[Mm][Oo][Vv]; do ffmpeg2theora "$file"; done
frabjous 2011年

是的,您绝对正确,我更正了我的答案。
Marcel Stimberg 2011年

1
您还可以设置nocaseglobbash选项以匹配小写,大写混合大小写的文件扩展名。
enzotib

谢谢!我以前从未使用过bash,但它看起来确实很有用。(我该去学习了!)
艾伦C

11

find . -iname '*.mov' -exec ffmpeg2theora '{}' \;

要限制递归深度,可以-maxdepth 1-exec


2
只是为了说明此答案与我的答案之间的区别:使用find还将在子目录中查找文件,for file in *.MOV解决方案将仅在当前目录中查找。
Marcel Stimberg 2011年
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.