Skip to content

Instantly share code, notes, and snippets.

@mkyutani
Last active March 8, 2016 08:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mkyutani/1aa2ebca2d5be1c24050 to your computer and use it in GitHub Desktop.
Save mkyutani/1aa2ebca2d5be1c24050 to your computer and use it in GitHub Desktop.
change-jpg-file-names.sh - Change jpg filenames using exif:DateTime
#!/bin/sh
PROGNAME=$(basename $0)
VERSION="0.3"
usage() {
echo "Usage: $PROGNAME [OPTIONS]"
echo
echo "Options:"
echo " -h, --help help"
echo " -V, --version version"
echo " -x, --exec execute"
echo
exit 1
}
execmode=0
for OPT in "$@"
do
case "$OPT" in
'-h'|'--help' )
usage
exit 1
;;
'-V'|'--version' )
echo "$PROGNAME Version $VERSION"
exit 1
;;
'-x'|'--exec' )
execmode=1
shift 1
;;
-*)
echo "$PROGNAME: illegal option -- '$(echo $1 | sed 's/^-*//')'" 1>&2
exit 1
;;
*)
echo "$PROGNAME: illegal parameter -- '$(echo $1 | sed 's/^-*//')'" 1>&2
exit 1
;;
esac
done
if [ $execmode = 0 ]
then echo '#### Not execution, just only print commands ####'
fi
n='(initial)'
c=0
for f in `ls -1 IMG_*.JPG`
do
p=$n
n=`identify -verbose $f | grep exif:DateTime: | sed 's/ *exif:DateTime: *\([0-9]\{4\}\):\([0-9]\{2\}\):\([0-9]\{2\}\).*$/\1\2\3/'`
if [ $n = $p ]
then c=`expr $c + 1`
else c=1
fi
if [ $execmode = 1 ]
then mv -v -i -b $f ${n}_`printf "%02d" ${c}`.JPG
else echo mv -v -i -b $f ${n}_`printf "%02d" ${c}`.JPG
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment