0

First command find and list jpeg/gif files with png extension. Second command convert a file to png.

  1. find . -type f -name "*.png" | xargs -L 1 -I{} file -i {} | grep -v 'image/png; charset=binary$'

  2. find . -name "*.jpg" -exec mogrify -format png {} \;

I to combine these two commands.

Rui F Ribeiro
  • 55,929
  • 26
  • 146
  • 227
Dhillon
  • 37
  • 3

1 Answers1

2
find . -type f -name '*.png' -exec bash -c '[[ "$(file -bi {})" != "image/png; charset=binary" ]] && mogrify -format png {}' \;

This command will find regular files with a png extension, and then execute mogrify -format png on every file if the mime doesn't match "image/png; charset=binary".

abitmol
  • 169
  • 2