What I need:
A command that deletes all .jpg
files in the current directory and subdirectories that have been taken with a RaspberryPi Camera.
(Ideally this should work with the Git Bash for Windows, but this would make it just more convenient and is therefore optional.)
What I tried:
I already used find . -name "*.jpg" -size 24k -delete
to delete thumbnails and I found out that the file
utility is able to display the camera manufacturer (manufacturer=RaspberryPi
).
Example:
$ file f49100889.jpg
f49100889.jpg: JPEG image data, Exif standard: [TIFF image data,
big-endian, direntries=10, height=0, manufacturer=RaspberryPi,
model=RP_OV5647, xresolution=156, yresolution=164, resolutionunit=2,
datetime=2015:06:09 08:15:03, width=0], baseline, precision 8,
1920x1080, frames 3
Background:
The filesystem of an NTFS-Drive got corrupted and I restored the files using testdisk/photorec. Now I've got the files but lost some metadata such as the directory structure and file-names. I restored the most important files from a backup already and would like salvage as much of the remaining data as possible. I need to delete some garbage files to make working with the rest easier.
Is it possible to combine these commands to achieve my goal? If yes, how? Is there a better way to go about this?
Thanks in advance!
Best Answer
Here's a simple way. Below are the contents of a script named
script.sh
in~/bin/
.Give it permission to execute (
chmod 0750 ~/bin/script.sh
). Then find the files and pass results, one at a time (using\;
, not+
) to the script.Another tool is
identify
from ImageMagick. This tool describes image characteristics and reads image data, including EXIF. It would be much slower thanfile
, but there's much more information in the image than the information provided byfile
. It could help whenfile
does not describe the data to be found. Its usage might be as follows.We can test the return code of
grep
(after usingfile
oridentify
in theif
statement, above) by displaying its return code. Fromman grep
:Combine this information with the knowledge that the
$?
variable contains the return code/value or exit code/value of the very last command executed.The lines above would produce a value of zero - match found - for
file
results that contain the string, "RaspberryPi".The lines above would produce a value of one - no match - assuming that
file
does not find a match for the string, "Rumpelstiltskin".