Is there a way to tell which files I accidentally renamed to *.jpg aren't actually JPEG images? I have a folder with many thousands of files, which due to an error had their extensions misnamed, all files now have the .jpg extension.
In all the .jpg files I would like to find the non-image files.
Is there a command-line way to identify which files are an actual image and which files are not?
I thought of looking for files without a preview, but cannot find a way to search files without a preview.
Here's an axample file that has a .jpg extension, but is not a real image:
You can use file FILENAME to determine the type of data in a file.
$ file image.jpg text.jpg pdf.jpg
image.jpg: JPEG image data
text.jpg:  ASCII text
pdf.jpg:   PDF document, version 1.4

So, file *.jpg | grep -v JPEG should give a list of all non-JPEGs with the &quot;.jpg&quot; extension
Also, assuming there are PDFs you can rename them in one go
find . -type f \
    -exec sh -c 'file &quot;$1&quot; | grep -q PDF' _ {} \;  \
    -exec sh -c 'echo mv -- &quot;$1&quot; &quot;${1%%jpg}pdf&quot;' _ {} \;

Remove the echo  in the second line once you verified that the output looks ok.