8

Hidden files and folders like .fseventsd, .Spotlight-V100, .TemporaryItems, and .Trashes are getting dumped in my flash drive every time I plug it into my Mac...

How do I keep it from doing this?

Related to How to disable creating .Spotlight-V100 and .Trash folders on external drive? and Prevent MacOS from making .* and ._* files!

Haywood
  • 81

2 Answers2

1

Macworld has an article describing a way to delete the hidden Mac dot files. The hints suggest modifying the default unmount script. Use care because the script could delete other hidden files like .bashrc that you may want.

http://hints.macworld.com/article.php?story=20110204124029798

Dave
  • 81
0

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
sage
  • 1,227