Disabling creation of unnecessary files on my external hard-drive?

I had an old mac that I decided to strip down for its hard-drive and RAM. I threw a shell on the hard-drive, and now I can connect it to my new mac with a USB cable.

Essentially I want to be using it like any other USB drive. However, mac keeps putting hidden files on it every time I plug it in:

drwxrwxrwx  1 user  staff  32768 Jun 16 09:31 .Spotlight-V100/
drwxrwxrwx@ 1 user  staff  32768 Jun 16 09:31 .Trashes/
-rwxrwxrwx  1 user  staff   4096 Jun 16 09:31 ._.Trashes*
-rwxrwxrwx  1 user  staff   4096 Jun 16 09:31 ._.com.apple.timemachine.donotpresent*
-rwxrwxrwx@ 1 user  staff      0 Jun 16 09:31 .com.apple.timemachine.donotpresent*
drwxrwxrwx  1 user  staff  32768 Jun 16 09:32 .fseventsd/

Is there any way to have all this disabled, or is it simply a side-effect of the fact that the drive came from a mac?


Solution 1:

Those files are created on other external drives as well.

The files that start with ._ are AppleDouble files that are used to store metadata like extended attributes and ACLs on unsupported filesystems. If the volume doesn't support the native formats, the AppleDouble files might get recreated even if you delete them. If the volume supports the native formats, the AppleDouble files are ignored, and you can either delete or merge them:

rm /Volumes/Volume/._*
dot_clean -f /Volumes/Volume # flat merge (default is recursive)

It's usually safe to delete the ._ files in any case. The .Trashes folder on my USB drive only had a com.apple.FinderInfo extended attribute:

$ sudo xattr -l /Volumes/WD/.Trashes
com.apple.FinderInfo:
00000000  00 00 00 00 00 00 00 00 40 00 00 00 00 00 00 00  |........@.......|
00000010  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  |................|

.com.apple.timemachine.donotpresent* files are not created if you enable this setting:

defaults write com.apple.TimeMachine DoNotOfferNewDisksForBackup -bool true

Spotlight can be disabled with mdutil -i off:

mdutil -i off /Volumes/Volume
rm -rf /Volumes/Volume/.Spotlight-V100

Deleting .DS_Store files:

find /Volumes/Volume -name .DS_Store -delete

This makes deleting files on the volume in Finder delete them immediately:

sudo rm -r /Volumes/Volume/.Trashes; touch /Volumes/Volume/.Trashes

BlueHarvest can remove most of those files automatically: