Acabei de investir algum tempo para tentar isso e criei o seguinte script:
#!/bin/bash
# set folder where files are located
SOURCE_FOLDER=/path/to/source
# define folder to which the files have to be copied
TARGET_FOLDER=/home/abcd
# ####
cd "${SOURCE_FOLDER}"
for FILE in *; do
# everything which is not a normal file
if [ ! -f "${FILE}" ]; then
echo "Skipping non-file: '${FILE}'"
continue
fi
# extract data from file structure
FILE_DATE=$(date -r "$FILE" '+%Y-%m')
FILE_DAY=$(date -r "$FILE" '+%d')
FILE_PREFIX=${FILE%%_*}
# skip files which do not match the naming convention
if [ "${FILE_PREFIX}" = "" -o "${FILE_PREFIX}" = "${FILE}" ]; then
echo "Skipping file with wrong naming: '${FILE}'"
continue
fi
# create target folder
TARGET="${TARGET_FOLDER}/${FILE_PREFIX}/${FILE_DATE}/${FILE_DAY}"
echo "Copy '$FILE' to ${TARGET}"
mkdir -p "${TARGET}"
cp "$FILE" "$TARGET"
done
Ele também cobre alguns casos especiais e verificações de probabilidade.