【问题标题】:Using find to open all files in subdirectories使用 find 打开子目录中的所有文件
【发布时间】:2013-05-08 15:01:21
【问题描述】:

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

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

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

我可以显示所有子目录:

find mockups -type d -print

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

谢谢!

【问题讨论】:

    标签: find


    【解决方案1】:

    我手头的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 {} +
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-08-19
      • 2015-05-26
      • 1970-01-01
      • 2017-03-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多