使用 Bash 查找递归检查非方形 jpg 图像尺寸,非常接近



我正在尝试递归循环遍历所有目录并打印所有不完全正方形的jpg文件的完整路径列表。

这是我用来查找 2 到 6 深度之间缺少封面的目录.jpg:

find . -mindepth 2 -maxdepth 6 -type d '!' -exec test -e "{}/cover.jpg" ';' -print

然后我修改了它以尝试找到非方形图像:

find . -mindepth 2 -maxdepth 6 -type d '!' -exec identify -format '%[fx:(h == w)]' "{}/cover.jpg" ';'

上面非常接近工作,它根据是否平方的结果开始输出 0 和 1,但 0 或 1 被输出到同一行而不是新行,它只是继续在同一行检查文件。

1111111111111111111111111111111001100101101110111001110010101001011000001101

我在想如果它每行输出一个 1 或 0,我可以在0的情况下 grep 它并打印文件路径。

我没有大量的Bash经验,到目前为止我没有运气。感谢任何帮助。

从 imagemagick 文档中,我认为您可以将换行符(和路径(附加到格式中:

find . -mindepth 2 -maxdepth 6 -type d '!' -exec 
identify -format '%[fx:(h == w)] %d/%fn' "{}/cover.jpg" ';' |
sed -n '/^0 / s///p'

(未经测试的代码,因为我没有安装图像魔术。sed命令实现 grep 并去除添加的前导零。

使用循环可能更容易。

find . -mindepth 2 -maxdepth 6 -type d '!' | while read file; do #Piping find results into loop
identify -format '%[fx:(h == w)]' "$file/cover.jpg" ';' #For each file, it runs the command you gave
printf "n" #Prints a new line
done

最新更新