Mar 09, '10 07:30:00AM • Contributed by: juanfal
Apple Finder has the custom of populating directories with those unavoidable .DS_Store files, volumes with .Trashes, and some files (especially pictures) with ._resources. The following interactive script will safely remove these files prior to copying.
#!/bin/sh
# bash script to clean (delete) Finder .DS_Store, .Trashes and ._resources
# Use cleandsstores.sh
# juanfc 2010-03-06
if [ $# != 1 ]
then
echo "ERROR: use\n\t`basename $0` dirtoclean"
exit 1
fi
res=`find "$@" \( -name ".DS_Store" -or -name ".Trashes" -or -name "._*" \) -print`
if [[ -z $res ]]; then
echo "nothing to delete"
exit 0
else
echo "Going to delete:"
echo $res
fi
read -p "Ok (yYsS1)?" ok
case $ok in
[yYsS1] )
find "$@" \( -name ".DS_Store" -or -name ".Trashes" -or -name "._*" \) -exec rm -rf "{}" \; -prune ;;
* )
echo "aborted."
esac
exit 0