Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.