使用find打开子目录中的所有文件

时间:2013-05-08 15:01:22

标签: find

请您帮我查找语法。我正在尝试复制此命令的效果,该命令将打开每个指定子目录中的所有文件:

open mockups/dashboard/* mockups/widget/singleproduct/* mockups/widget/carousel/*

我想让它适用于模型下面的任何子目录。

我可以用:

显示所有子目录
find mockups -type d -print

但我不确定如何使用xargs添加“*”。另外,我不想为每个文件单独执行打开“-exec open {} \;”,因为它启动了50个不同的Preview副本,当我需要的是一个预览实例,其中加载了50个文件

谢谢!

1 个答案:

答案 0 :(得分:2)

我手头的find版本允许在+参数后指定-exec符号:

从手册页:

-exec command {} +
              This variant of the -exec action runs the specified command on the 
              selected files, but the command line is built by appending each 
              selected file name at the end; the total number of invocations of 
              the command will be much less than the number of matched files.  
              The command line is built in much the same way that xargs builds 
              its command lines.  Only one instance of `{}' is allowed within 
              the command.  The command is executed in the starting directory.

这意味着尽可能少地执行open实例,例如:

find mockups -type f -exec open {} +