Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

When plugging a USB stick into a Mac, OS X creates a number of hidden files on the stick, including a Spotlight index and Trash folder.

Example from the terminal for a USB stick "Untitled":

$ ls -a /Volumes/Untitled
.Spotlight-V100
.Trashes
._.Trashes
.disk
.fseventsd

It even does this on the xD memory card for my camera, so after having copied my pictures and deleted them from the card, the card is still full.

Is it possible to turn this off for USB and memory cards, so OS X either writes these files to the primary disk or doesn't write them at all?

share|improve this question
    
Sidenote: A journaled filesystem automatically generates these files. While indexing isn't integral to journaling, fseventd, for example, is. Though an HFS+ scheme has its benefits (IE, lack of fragmentation), you've pointed out one of its drawbacks. If you format the drive as exFAT or FAT32, it would both be compatible and solve your issue. The current solutions provided are all, essentially, different methods to unjournal a journaled format. –  njboot May 10 at 10:30

13 Answers 13

up vote 13 down vote accepted

As I know you have 2 choices :

  1. TinkerTool (free)

alt text

  1. BlueHarvest (commercial)

alt text

share|improve this answer
    
OK, thanks. Was kind of hoping that there would be a built-in setting somewhere, but at least there's a solution available. –  j-g-faustus Jan 20 '11 at 18:08
    
@j-g: Tinkertool shows the system settings in a GUI interface as opposed to CLI, which can be harder to use for a lot of people. –  Philip Regan Jan 20 '11 at 18:28
1  
@Philip: Unfortunately Tinkertool only deals with .DS_Store files according to their detail page, which presumably means that this is the only hidden file that can be disabled through the CLI - the other files need custom tools. But BlueHarvest looks nice, and does what I need. (Found some more details on the issue here and here) –  j-g-faustus Jan 20 '11 at 18:47
    
outdate! later answers are better –  qarma Aug 19 '13 at 9:46
    
@j-g-faustus Not only Tinkertool only deals with .DS_store files but it does so just for network fileysystems –  nhed Apr 14 at 16:23

For just a particular mounted volume - like a flash drive called yourUSBstick in this example - these commands will remove existing cruft, stop Spotlight indexing now and in the future, stop the related fsevents logging, and disable the Trash feature.

mdutil -i off /Volumes/yourUSBstick
cd /Volumes/yourUSBstick
rm -rf .{,_.}{fseventsd,Spotlight-V*,Trashes}
mkdir .fseventsd
touch .fseventsd/no_log .metadata_never_index .Trashes
cd -

Other unfamiliar stuff you may still see you probably want to keep, like Apple double "._*" files and other Apple DS cruft relating to icons and window placement.

share|improve this answer
2  
While this may disable indexing, those files and directories will still be present on the volume (which is the annoying part in the first place), and if you delete them .Spotlight* and .fseventd will come back. In fact, .metadata_never_index is one more entry in the file listing than the usual cruft. –  ShreevatsaR May 21 '11 at 8:02
    
+1, Actually, I came up with he idea of touching trashes myself and went here for a better solution, but having seen this one couldn't resist +1 it. It solves the real problem — stopping car audio from playing trashed files ;) –  Michael Krelin - hacker Feb 1 '12 at 19:33
    
+1 knew this existed but always have to find it when I need it. This is useful if you have more access to the USB drive than to the OSX system. –  Matthew May 30 at 13:00

Another way to deal with (just the) spotlight files, is to add that volume to your Spotlight exclude list. Plug the device in, and go to the Spotlight prefpane in System Preferences. Select the Privacy tab. Now drag that volume from your desktop up into the privacy list.. or use the + button at the bottom to add it. No more spotlight indexing will happen on that volume.

share|improve this answer
    
Thanks, I'll try that. –  j-g-faustus Jan 21 '11 at 8:16

To keep Spotlight from indexing non system volumes, add /Volumes to the Privacy list in System Preferences > Spotlight.

/Volumes is the point in the file system where all non-system disks are mounted by default.

enter image description here

share|improve this answer
    
impossible to add /Volumes in 10.8; it's possible to add individual volumes one at a time though. I suspect it's similar to mdutil -i off /Volumes/xxx –  qarma Aug 19 '13 at 9:47
  1. Insert the USB drive.
  2. Navigate to Macintosh HD > Applications > Utilities and open Terminal.
  3. At the Terminal prompt, type the following command, replacing path_to_volume with the real path:

    sudo mdutil -i off /path_to_volume

  4. Press return.

  5. If prompted for a password, type your admin password, then press return. You will receive the response:

    /path_to_volume/: Indexing disabled for volume. in Mac OS X 10.4 or

    /path_to_volume: Indexing disabled. under Mac OS X 10.5 or later.

    Spotlight will immediately cease to index the specified volume.

  6. If you are using Mac OS X 10.5 or later, skip to step 9.

  7. At the Terminal prompt, type the following command, again substituting the correct path:

    sudo mdutil -E /path_to_volume and press return

  8. If prompted for a password, type your admin password, then press return. You will receive the response:

    /path_to_volume/: Volume index removed.

  9. At the Terminal prompt, type exit then press return.
  10. Quit Terminal.

Thanks to thexlab.com, their troubleshooting Mac OS X e-books, and their website for the detailed explanation of why other methods sort of work.

share|improve this answer
    
Note sudo asks for the current user's password –  Mark Feb 16 '13 at 8:21

I use the MacOS Terminal command line to list and delete all these files and folders before ejecting the device from the desktop. For some files, you may have to sudo the /bin/rm command.

share|improve this answer
    
That's what I do too. Although it would be even better if I didn't need to, so I'm investigating the alternatives. –  j-g-faustus Jan 20 '11 at 20:26
    
By the way, the device is found somewhere at /Volumes/<name> –  DerMike Jan 21 '11 at 11:31

I use Clean Eject (free) and a custom Automator Service (still private) so I can assign a hotkey to clean & eject a volume using the app.

share|improve this answer
    
Without access to the Automator Service you mentioned this answer isn't actually very helpful. Can you share the service as well? –  patrix Jan 9 at 10:54
    
The answer is absolutely helpful - you can use the app without the Automator action. If you want to add a special shortcut key for Clean Eject then you have lots of options: Alfred, Keyboard Maestro. The Automator action is not essential, but is useful. I will upload it when I can to: gingerbeardman.com/services –  matt Jan 10 at 12:35
    
The service I use to Clean Eject selected finder volumes is now uploaded to by site (see above for link). –  matt Jan 10 at 12:56
    
Thanks for the upload, makes the answer much more complete. –  patrix Jan 10 at 13:25

I ended up using a free app "Hidden Cleaner". My car's MP3 player was trying to read .(MP3filename).mp3 (hollow, empty mp3 files) as well. Go to Macintosh HD in Devices section on the Finder left hand menu and drag your USB drive and drop onto the Hidden Cleaner app. It will cleanup the hollow files and leave the real MP3s and will eject your USB.

Note: That is not a permanent solution. You need to do above everytime you copy files. I don't mind though.

share|improve this answer

An easy way to stop my car audio trying to read hidden Mac OS files is to remove them in Windows OS. Simply copy your MP3 music to the USB stick from iTunes. Swap the stick into Windows OS and select view hidden files from folder options. This will then allow you to delete every single hidden file that your trusty Mac placed on your USB stick including those pesky .trashes files. Finally a use for Windows OS!

share|improve this answer

Actually touching the .Trashes file will be the best way to solve your main problem since .Trashes is now a file instead of a folder. This means that Apple can't relocate the files to the .Trashes folder when you delete them and your drive is no longer full.

Another option is to hit Cmd-Opt-Shift-Backspace to force Finder to empty the .Trashes content on the card before you eject it.

The first method is really the best as the second affects all Trash contents on all drives.

However, it seems from your post that you are more worried about the pollution of the drive by the various dot files. If you follow the steps mentioned above, you'll save your disk space, but there will be a minimum of dot files created.

share|improve this answer

This should really be a comment, but I don't have enough points to actually comment so I had to write a separate answer.

If a moderator could move this to the right location (or somehow give me 50 reputation so that I could comment) I would really appreciate it. :)

Anyway here's what I wanted to say:

~ ~ ~ ~ ~ ~ ~

@ Miles Leacy's post

and @ qarma's comment:

No, this is still possible even in OSX 10.9, but you need to do a few extra steps now:

1) In Finder click Go then click Go To Folder...

2) Type /Volumes and click Go.

3) A Finder window will open, and it should say Volumes at the top.

This is the most important step:

4) Next to where it says Volumes at the top of the Finder window, there is a tiny blue folder icon. Click and drag this icon left into your Favorites panel.

5) Now you will have access to your Volumes folder anywhere, including in Spotlight settings like Miles Leacy suggested. (Whenever you need it, just click on the Favorites link to select it.)

Hope this helps,

Best,

Vlad :)

~ ~ ~

How to add the Volumes folder to your Favorites so that you can access it in the Spotlight settings

~ ~ ~

What it looks like after adding the Volumes folder to the Spotlight exceptions list:

Notice in the background you can see my post in Safari. ;)

What it looks like after adding the Volumes folder to the Spotlight exceptions list

share|improve this answer

Old question, but I, finally, discovered Asepsis. This is an open source utility that solves this age-old problem by confining all the .DS_STORE directories in one place, by default /usr/local/.dscage
After installation, and a reboot, no more .DS_STORE on USB drives, with the advantage (for some of us) of not having to disable indexing on external drives. Since version 1.4 it also supports OS X Mavericks.

share|improve this answer

it can't work.

no way to resolve this problem.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.