#!/bin/bash set -e IFSBKP=$IFS IFS=$'\n' BASE_PATH="/net/server-sync" DIRS=($(find $BASE_PATH -maxdepth 5 -type d -name '.Trash*')) DIRLEN=${#DIRS[@]} if [ ${DIRLEN} -lt 1 ]; then echo "Nothing to remove..." exit 0 fi echo "Dirs to remove:" echo "~~~~~~~~~~~~~~~" for (( i=0; i<${DIRLEN}; i++)); do SIZES[$i]=$(du -hs ${DIRS[$i]}|cut -d$'\t' -f1) echo $(($i+1)):${DIRS[$i]} ${SIZES[$i]} done; echo "---------------" echo -n "Remove all? y/N (next question asks about selective remove) " read resp if [ "x$resp" = "xy" ]; then echo "Removing all..." for (( i=0; i<${DIRLEN}; i++)); do echo "Removing $(($i+1))/${DIRLEN} ${DIRS[$i]} ${SIZES[$i]}" rm -rf ${DIRS[$i]} done; echo "Done!" else echo -n "Remove any? y/N " read resp if [ "x$resp" = "xy" ]; then for (( i=0; i<${DIRLEN}; i++)); do echo -n "${DIRS[$i]} (${SIZES[$i]}) Remove? y/N " read resp if [ "x$resp" = "xy" ];then rm -rf ${DIRS[$i]} fi done; echo "Done!" else echo "Cancelled.." fi fi IFS=$IFSBKP exit 0