#!/bin/bash
# This script will recursively search for and remove all files case
# insensitively matched against the content of the variable UNWANTED. It is
# thought of as a way of removing files created by foreign operating systems,
# i.e. Apple's .AppleDB and lots of others.
declare -ra UNWANTED=(".appledb" ".appledesktop" ".appledouble" ".ds_store" "._.ds_store" ":2eDS_Store")
declare -r DIR=${1:-.}
echo $DIR
if test -d $DIR
then
echo "Performing cleanup of files in $DIR that case insensitivley match \"${UNWANTED[*]}\""
FIND_OPTION="\( -iname \"${UNWANTED[0]}\""
NAME_NUMBER=${#UNWANTED[*]}
for I in $(seq $((NAME_NUMBER-1)))
do
FIND_OPTION="$FIND_OPTION -or -iname \"${UNWANTED[I]}\""
done
FIND_OPTION="$FIND_OPTION \)"
echo $FIND_OPTION
find $DIR $FIND_OPTION -exec ls -l {} \;
else
echo "$DIR does not exist! exiting..."
exit 1
fi
exit 0