如何获取每个子目录中与文件扩展名列表匹配的第一个文件?我的目标是仅对一系列子目录中的任何一个文件运行程序。
例如,下面有3个子目录。我想在 subdir1/file.dat、subdir2/file.d01 和 subdir3/file1.dat 上运行该程序,因为我想查找扩展名为 .dat 或 .d01 的文件。
subdir1 - file.dat, file.d01
subdir2 - file.d01, file.d02, file.d03
subdir3 - file1.dat, file2.dat
Run Code Online (Sandbox Code Playgroud)
以下内容在一段时间内效果很好,直到我开始遇到像最后两个这样的目录。subdir3 是有问题的,因为所有文件最终都会被处理。
find . -name "*.dat" -exec mixb {} \;
Run Code Online (Sandbox Code Playgroud)