0

I am trying to recursively loop through all directories and print a full path list of all jpg files that are not perfectly square.

here is something I was using to find directories between 2 and 6 deep that are missing a cover.jpg:

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

I then modified that to try and find the non square images:

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

The above is very close to working, it starts outputting 0 and 1 based on the result of being square or not, but the 0 or 1 is output to the same line instead of a new line, and it just continues on the same line as it checks the files.

1111111111111111111111111111111001100101101110111001110010101001011000001101

I was thinking if it output a single 1 or 0 per line I could grep it if 0 and print the file path.

I don't have a ton of Bash experience, and so far I am having no luck. Appreciate any help.

shellter
  • 36,525
  • 7
  • 83
  • 90
Jieiku
  • 489
  • 4
  • 15

2 Answers2

2

From the imagemagick documentation, I think you can just append the newline (and path) to the format:

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

(Untested code as I don't have imagemagick installed. The sed command implements the grep and strips the leading zero that was added.)

jhnc
  • 11,310
  • 1
  • 9
  • 26
1

It might be easier to do with a loop.

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
guninvalid
  • 411
  • 2
  • 5
  • 16