I like the general concept in the Macworld article referenced by @Dave, but I don't want to nuke intentionally placed hidden files or folders (especially .git or .svn) and I want to clean up non-msdos filesystems as well as dos.
Note that this will cause scripted deletion/destruction of your files, so I recommend you only do this if you pretty much comprehend what this script does and you're OK with potential mayhem.
I took their suggested script and changed it as shown below. As they said there, before editing make sure to sudo mv /sbin/umount /sbin/umount-orig
(so this script can invoke the original umount). After editing, sudo chmod 555 /sbin/umount
and sudo chown root:wheel /sbin/umount
.
#!/bin/sh --
loggerTag='umount-wrapper'
(
if [ "$@" ]; then
for i in "$@"; do
echo $i
done
echo "cleaning mounted filesystem before running umount-orig..."
rm -rf "$1"/._*
rm -rf "$1"/.Trash*
rm -rf "$1"/.Spotlight*
rm -rf "$1"/.DS_Store
rm -rf "$1"/.fseven*
fi
) | logger -st $loggerTag
/sbin/umount-orig "$@"
For reference (in case the link disappears), the original said to use the following to clean up, but depending on filesystem type:
fstype=`diskutil info "$1" | sed 's/ //g' | grep '^Type:' | cut -d':' -f2`
echo "fstype is ${fstype}"
if [ "$fstype" = "msdos" ]; then
echo cleaning msdos filesystem...
find "$1" -depth -name '.[^.]*' -print -exec /bin/rm -fr {} \;
else
echo not msdos, skipping to umount...
fi
chflags hidden
to hide them.._
files are the only hidden files regularly created that aren't mentioned in this topic.