This is how to sort files into date separated folders.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
BASE_DIR=/var/www/owncloud.heimdaheim.de/data/christian/files/oldgallery
SORT_DIR=/var/www/owncloud.heimdaheim.de/data/christian/files/datedgallery

find "$BASE_DIR" -type f -name "*" | while IFS= read -r file; do
  year="$(date -d "$(stat -c %y "$file")" +%Y)"
  month="$(date -d "$(stat -c %y "$file")" +%b)"
  filestamp="$( date -d "$( stat -c %y "$file")" +%Y%m%d)"
  [[ ! -d "$SORT_DIR/$year/$month" ]] && mkdir -p "$SORT_DIR/$year/$month";
  mv "$file" "$SORT_DIR/$year/$month/${filestamp}_${file##*/}"
done