#!/bin/bash Src=${1} Days=${2} if [ "${Src}" == "" ] then echo "Usage: $0 []" exit 1 fi if [ "${Days}" == "" ] then Days=30 fi declare -A Settings=() Settings[Src]=${Src} Settings[PruneDate]=$(date -d "${Days} days ago" '+%Y-%m-%d') src=${Settings[Src]} prune_date=${Settings[PruneDate]} echo "Finding files older than ${prune_date}..." Cmd="find ${src} -type f ! -newermt \"${prune_date}\"" echo ${Cmd} files=($(eval ${Cmd})) total_files= ${#files[*]} if [[ ${total} == 0 ]] then echo "No files found to be pruned. Bye..." exit 0 fi echo Before Pruning.... duf ${src} echo "The following files will be removed:" echo "====================================" for f in $files ; do echo $f; done echo "====================================" echo "Total files to be pruned: ${total_files}" Cmd="${Cmd} -delete" echo ${Cmd} eval ${Cmd} echo "Removing empty directories..." Cmd="find ${src} -type d -empty -print -delete" echo ${Cmd} eval ${Cmd} echo After Pruning.... duf ${src} echo $0 Done