Skip to content

Instantly share code, notes, and snippets.

@ernestom
Created February 10, 2013 08:54
Show Gist options
  • Save ernestom/4748914 to your computer and use it in GitHub Desktop.
Save ernestom/4748914 to your computer and use it in GitHub Desktop.
Fix imgur mistakes :( These one liners rename files with jpg extension to gif extension if their mime type is image/gif, after replacing spaces with underscores and jpeg with jpg.
#!/bin/bash
# depends on `brew install rename`
cd ~/Pictures/pics
find . | rename 's/\ /_/g'
find . -iname '*.jpeg' | rename 's/jpeg$/jpg/g'
find . -iname '*.jpg' -exec file -F '' --mime {} \; \
| grep -i 'image/gif' | awk '{print $1}' \
| while read file; do bn=`basename -s .jpg $file`; mv $bn.jpg $bn.gif; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment