Skip to content

Instantly share code, notes, and snippets.

@karlding
Created August 16, 2017 03:32
Show Gist options
  • Save karlding/9d7ab0ff3a4426339e968a77e2b4a2f8 to your computer and use it in GitHub Desktop.
Save karlding/9d7ab0ff3a4426339e968a77e2b4a2f8 to your computer and use it in GitHub Desktop.
Deleting the JPG previews while keeping the DNGs

On my Nexus 5, I started shooting in RAW mode with JPG previews. However, when I copy the DNGs over to my laptop for editing/archival, I don't care about the JPG files.

The camera app creates two files:

  1. filename.jpg: the JPG preview
  2. filename.dng: the RAW file

Basically, we want to remove any JPG files for which a RAW file also exists. I just use this bash one-liner (which I run in bash for Windows).

 for img in *.jpg; do [[ ! -f "${img%.jpg}.dng" ]] || rm -- "$img"; done

Basically, for each image that matches the *.jpg globbing pattern, it tests whether a dng file does not exist (by stripping off the .jpg extension and adding .dng. If this test succeeds, then the exit code is 0 and the command doesn't continue. Otherwise, it removes the JPG preview image.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment