Skip to content

Instantly share code, notes, and snippets.

@kamranzafar
Last active January 1, 2016 07:59
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 kamranzafar/8115604 to your computer and use it in GitHub Desktop.
Save kamranzafar/8115604 to your computer and use it in GitHub Desktop.
A simple shell script that organizes media files in date folders.
#!/bin/bash
# A simple shell script that organizes media files in date folders.
# This script uses exiftool that can be installed using "sudo apt-get install libimage-exiftool-perl"
for file in *.{jpg,JPG,3gp,3GP,png,PNG,mp4,MP4,mov,MOV};
do
datepath="$(exiftool -s -G "$file" | grep '\[EXIF\].*ModifyDate' | awk '{print $4 }' | sed s%:%/%g)"
if [ -z $datepath ]; then
datepath="$(exiftool -s -G "$file" | grep 'FileModifyDate' | awk '{print $4 }' | sed s%:%/%g)"
fi
if ! test -e "$datepath"; then
mkdir -pv "$datepath"
fi
#mv --backup=t -v "$file" $datepath # preserve backup
mv -v "$file" $datepath
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment