遍历文件夹中的所有文件夹和 运行 命令

Loop through all folders within a folder and run command

我有一个 .png 文件,我错误地将其另存为 .psd 并埋在资产目录的某个地方。我想出了如何通过 file -I /pathWithFileName 打印文件的实际类型,它在我的桌面上打印出 'Untitled-1.png: image/vnd.adobe.photoshop; charset=binary' 这是正确的,因为我故意犯了错误来测试。

现在我想 运行 它在我的整个资产目录中,包括所有子文件夹 .imagesets 但这并不能完全解决问题:

find /mypath/Assets.xcassets/foldername/_foldername -type f -maxdepth 2 for i in *.imageset; file -I *.jpg ;

这行不通。关于如何遍历所有 Assets.xcassets 个文件夹并打印出文件 -I /pathWithFileName 以便我可以看到哪个图像保存错误的任何想法?

使用 -path 选项匹配以 .imageset 结尾的目录中以 .psd 结尾的文件。然后使用 -exec 选项对文件 运行 执行命令。

find /mypath/Assets.xcassets/foldername/_foldername -type f -maxdepth 2 -path '*.imageset/*.psd' -exec file -I {} +