Skip to content

Instantly share code, notes, and snippets.

@coreyti
Created October 5, 2008 09:25
Show Gist options
  • Save coreyti/14867 to your computer and use it in GitHub Desktop.
Save coreyti/14867 to your computer and use it in GitHub Desktop.
Converts DSC_NNNN.JPG to something like 2008.Jan.01_NNNN.jpg, where the date prefix is derived from the file modification date
#!/bin/bash
###############################################################################
# Nikon image filename conversion, e.g. (DSC_NNNN.JPG to 2008.Jan.01_NNNN.jpg)
###############################################################################
# change any spaces to underscores
for i in * ; do
if [ -f "$i" ] ; then
echo mv \"$i\" ${i// /_}
fi
done
# lowercase the extension
for i in `ls -1 *.JPG` ; do echo mv $i ${i%.*}.jpg | sh ; done
# change DSC prefix to date prefix
for i in `ls -1 DSC*` ; do prefix=`ls -lT $i | awk '{print $9"."$6"."$7}'` ; suffix=`echo ${i#*_}` ; echo mv {DSC,$prefix}"_"$suffix | sh ; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment