#!/bin/bash # 200k pictures in one directory. Whoops. IN="./input" OUT="./output" for file in $(find "${IN}" -maxdepth 1 -type f -printf '%f\n'); do year=${file:0:4} month=${file:4:2} day=${file:6:2} echo $file $year $month $day source="${IN}/${file}" target="${OUT}/${year}/${month}/${day}/${file}" mkdir -p $(dirname "${target}") if [ ! -e "${target}" ]; then mv "${source}" "${target}" fi done