So I have a folder with thousands of image files, all of them saved as .jpg
.
The problem is that some of those files are actually PNG image files, so they don't open in a lot of programs, unless I manually change their extension to .png
. For example, the Ubuntu image viewer throws this error:
"Error interpreting JPEG image file (Not a JPEG file: starts with 0x89 0x50)"
I've already ran a hexdump of some of these files to confirm this error and it checks out.
I'm looking for a simple way to find all the files with the wrong extension among the other files and change their extension. How would I do this with a bash script for example? So far I have no idea. All help apreciated!
open
attempts to parse the file data and that it relies on the file extension to be correct. A simple 'generic'open
will always succeed on an existing file. A 'smart'open
will ignore the file extension and use the file's magic signature to determine its type and may therefore succeed. – Mcgough