Disable and Remove .DS_Store Files

In a number of environments, where SMB, AFP and other file sharing protocols are used with Mac OS X, Windows and Linux clients, there are a number of hidden files that Mac OS X leaves behind. For anyone who has managed an environment like this you’re likely to notice the .DS_Store files and potentially even have tried taking measures to get rid of them. However, try as you might they’re likely to have come back repeatedly. But you don’t have to live with them.

You can tell your Windows clients not to show hidden files.  From Windows XP, open an explorer.exe window (Windows Explorer, also accessible by browsing any folder on the hard drive) and from here click on the View tab and then click on Do not show hidden files and folders.  For Vista and up, click on the Folder Options control panel and then choose the View tab and then click on Do not show hidden files and folders.

But if this is proving unwieldy then you can tell each Mac OS X user account not to make them.  This isn’t to say that you should – this is how Mac OS X tracks the view and icon placements of a folder.  But if you need to get rid of them you need to get rid of them…  To do so you’re going to create a file called com.apple.desktopservices.plist in the ~/Library/Preferences of each user account that contains the following:

{
DSDontWriteNetworkStores = true;
}

The easiest way to go about this is to simply run the following command for each user on each system:

defaults write com.apple.desktopservices DSDontWriteNetworkStores true

You can use the com.apple.desktopservices.plist as a managed preference, or for future users you can also go ahead and add the file to the user template by dropping it into /System/Library/User Template/English.lproj/Library/Preferences.

While this will keep new .DS_Store files from being generated on network volumes (aka NetworkStores) it will not do so for local volumes, including those on an Xsan (since Xsan volumes are basically interpreted by the finder as a local volume in this context).  It’s also worth noting that you’ll probably need to reboot after you run these commands.

Once you’ve disabled the creation of new .DS_Store files you’ll more than likely want to eliminate the ones that are already on your volume.  To do so, you can use the find command in conjunction with the -name flag and -exec flag followed by rm as follows (replacing /path/to/share with the path to your actual share):

find /path/to/share -name .DS_Store -exec rm {} ;

For the above command to process correctly you’ll need the account it’s run as to be able to access files in all folders of the tree where a .DS_Store file may exist.  If you find that new .DS_Store files are created after this is all complete, then look at the owner of the new files.  Typically you’ll find a user account was skipped and it’s the user who is listed as the owner of the new .DS_Store files.

  • Pingback: SSHFS on Mac OS X 10.6.8 and 10.7.2 with Fuse4X » Philipp Klaus's Computing Blog()

  • Mr.Vlad

    hi, its normal have a file with plist00?_DSDontWriteNetworkStoresTtrue content instead
    {
    DSDontWriteNetworkStores = true;
    }
    i ran the command, and cat command show me the file like an binary file, it’s correct?

    Regards.. PD usefull post!

    • http://www.krypted.com Charles

      Ya, you have to use defaults to read the contents or they’ll show as binary.