Last active
April 19, 2021 14:45
-
-
Save shrubb/740e46979ca8d5bc1c2b44350994fd02 to your computer and use it in GitHub Desktop.
Rename photos with EXIF dates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# usage: | |
# $ ls | |
# 2.23.1.jpeg 2.23.jpg DSC_0383.JPG DSC_0411.JPG DSC_0439.JPG DSC_0467.JPG | |
# DSC_0496.JPG DSC_0524.JPG DSC_0553.JPG DSC_0582.JPG DSC_0610.JPG DSC_0638.JPG | |
# DSC_0384.JPG DSC_0412.JPG DSC_0440.JPG DSC_0468.JPG DSC_0497.JPG DSC_0525.JPG | |
# ... ... ... | |
# DSC_0611.JPG DSC_0639.JPG DSC_0357.NEF DSC_0385.JPG DSC_0413.JPG DSC_0441.JPG | |
# DSC_0554.JPG DSC_0583.JPG DSC_0358.NEF DSC_0386.JPG DSC_0414.JPG DSC_0442.JPG | |
# $ ./../rename.sh | |
# shopt -s nullglob | |
shopt -s nocaseglob | |
OMP_NUM_THREADS=1 | |
for file in *.{nef,jpeg,jpg}; do | |
datetime=$(identify -format %[EXIF:DateTimeOriginal] $file) | |
if [ $? -eq 0 ]; then | |
datetime=$(echo $datetime | awk -- '{ gsub(/[ :]/, "_"); print }') | |
# new_filename="$datetime.${file##*.}" # 2019_05_20_10_41_09.NEF | |
new_filename="${datetime}_${file}" # 2019_05_20_10_41_09_DSC_0341.NEF | |
if [ -f $new_filename ]; then | |
echo "File $new_filename already exists, not moving $file" | |
else | |
mv $file $new_filename | |
fi | |
else | |
echo "No $file files" | |
fi | |
done | |
shopt -u nocaseglob | |
# shopt -u nullglob |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment