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.

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".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.