Cleaning out wannabe Jpegs

Published On: 2012-10-23

Category: Jargon Jabberwocky

#!/bin/bash

# A script to help with the error message:
# gd-jpeg: JPEG library reports unrecoverable error: Not a JPEG file: starts with 0x47 0x49
# run this in a directory where your images reside and it will recursively find all jpegs that aren't jpegs.

OIFS="$IFS"
IFS=$'\n'
for file in `find . -name '*.jpg' -or -name '*.JPG'`
do
  test=`xxd -l 2 -p -u "$file"`
  if [ "$test" != "FFD8" ]
  then
    echo -n "$file "
    xxd -l 2 -p -u "$file"
  fi
done
IFS="$OIFS"