Organizing Media files on Linux

Recently I was doing some cleanup on my Dropbox account, and I found that some folders (especially “Camera Uploads”) had like a million unorganized images and video files that were auto uploaded from my mobile phone and other devices. Unfortunately Dropbox doesn’t automatically organize these files in date folders or even gives you an option to do so. So I decided to write a script to organize the files myself in the Dropbox folder on my Linux Desktop. Below is a simple shell script that can do this.

for file in *.{jpg,JPG,3gp,3GP,png,PNG,mp4,MP4,mov,MOV};
do
datepath="$(exiftool "$file" | grep Modification | awk '{print $5 }' | sed s%:%/%g)"
if ! test -e "$datepath"; then
mkdir -pv "$datepath"
fi

mv -v "$file" $datepath
done

This script moves the media files in date folders, which are created using the last modified date of the file. The script is also available on Github and uses exiftool to determine the last modified date. The exiftool can be installed on Ubuntu using the following command:

sudo apt-get install libimage-exiftool-perl

Leave a Reply