I want to delete every RAW image file (Photo image) that has no JPG counterpart.
Here's my current workflow:
- My camera creates a RAW and a JPG for every photo I take.
- I review the JPG files, and delete the ones I don't want (Since JPGs load much faster)
- I currently manually go thought the folder, selecting any RAW file (*.cr3 in my case) that doesn't have a JPG pair (Because I deleted the JPG in the review process).
Example of what the files look like before I review them:
IMG_001.JPG
IMG_001.CR3
IMG_002.JPG
IMG_002.CR3
IMG_003.JPG
IMG_003.CR3
IMG_004.JPG
IMG_004.CR3
Example of what files look like after I've reviewed them
IMG_001.JPG
IMG_001.CR3
IMG_002.CR3
IMG_003.JPG
IMG_003.CR3
IMG_004.CR3
Both IMG_002 and IMG_004 are missing a jpg counterpart, meaning I deleted that jpg counterpart, and now I want to delete the raw file.
I've tried to follow the advice here: and here: but to no avail.
This is my code right now:
for files in RAW/*
do
test="JPG/$(basename ${files::9})JPG"
if [ ! -f "$test" ]
then echo "$files"
fi
done
or, the slick one-line version:
for files in RAW/*; do if [ ! -f "JPG/$(basename ${files::9})JPG" ]; then echo "$files"; fi done
or, the other one liner:
For files in RAW/*; [ ! -f "JPG/$(basename ${files::9})JPG" ] && echo "JPG/$(basename ${files::9})JPG"
The code assumes the raw and jpg files are in separate folders, which is fine. having them in the same folder is slightly more convenient, though.
Basically, I want to know how to write this script. I'm using the terminal on Mac OSX 15 Catalina.