#!/usr/bin/env bash DATE_RANGE="45" IN="/main/staging/rss/" OUT="/main/audio/shared" TARGET_DATE=$(($(date +%s) - (3600*24*$DATE_RANGE))) rm /tmp/list.txt 2>/dev/null find "${IN}" -iname "*.mp3" -print0 | while read -d $'\0' file do fileName=$(basename "${file}") fileDate=$(echo $fileName | cut -c1-10) fileTime=$(date --date "${fileDate}" +%s) relPath=$(realpath "${file}" | cut -c$((${#IN} + 1))-) if [[ $TARGET_DATE -le $fileTime ]]; then echo $relPath >> /tmp/list.txt else rm "${OUT}/$relPath" 2>/dev/null fi done rsync -aP --no-relative --files-from=/tmp/list.txt "${IN}" "${OUT}"