[英]How to script to go to the deepest folder directory from parent directory to execute a command?
我试图通过ovftool自动将.vmx转换为.ova,这些.vmx文件是从ghettoVCB生成的。 因此,我正在编写脚本以使转换自动化工作。
我的问题是如何编写一个shell脚本,该脚本从parent_directory遍历每个目录并在每个目录中执行命令? 还是可以将所有内容从最深的文件夹移到parent_directory? (此解决方案将这些文件从最深的文件夹移动到parent_directory可能会很耗时)。
目录结构如下:parent_directory / automation / automation-2016-04-18_19-08-32 / automation.vmx parent_directory / bulls / bulls-2016-04-18_18-28-57 / bulls.vmx
这是另一种结构布局
parent_directory
parent_directory中子文件夹的名称不遵循模式。 可以是任何名称。 文件夹“ automation-2016-04-18_19-08-32”是子文件夹的名称+日期+时间。
将所有内容从最深的文件夹移至parent_directory
此命令将搜索当前目录的子目录,找到所有.vmx
文件,并将它们移动到当前目录:
find . -type f -name '*.vmx' -exec mv {} . \;
编写一个shell脚本,该脚本从parent_directory遍历每个目录并在每个目录中执行命令
以下命令将搜索当前目录的每个子目录并在其中执行command
:
find . -type d -execdir command \;
如果要在每个包含.vmx
文件的目录中运行command
并提供这些.vmx
文件的名称作为command
参数,请运行:
find . -type f -name '*.vmx' -execdir command {} +
或者,假设我们要为找到的每个.vmx
文件运行一次命令:
find . -type f -name '*.vmx' -execdir command {} \;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.