Tips and tricks

Move files based on creation date

Simple bash script that moves jpg files to week folder.

#!/bin/bash

sourcedir=”/”
destdir=”/”

today=`date ‘+%Y%m%d’`
folder=`date ‘+%y-%V’`
touch -t “$today”0000.00 /tmp/today.start
touch -t “$today”2359.59 /tmp/today.end

if [ ! -d $destdir/$folder ]; then
mkdir -p $destdir/$folder
echo “Creating $destdir/$folder”
fi

find $sourcedir -maxdepth 1 -name “*.jpg” -type f -cnewer /tmp/today.start -and -not -cnewer /tmp/today.end -exec mv -v {} $destdir/$folder/ \;

rm /tmp/today.start /tmp/today.end
#