我正在尝试递归地遍历所有目录,并打印所有非理想正方形的jpg文件的完整路径列表。
这是我用来查找2到6之间深的目录而缺少cover.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/%f\n' "{}/cover.jpg" ';' |\
sed -n '/^0 / s///p'
((未经测试的代码,因为我没有安装imagemagick。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