How to remove .DS_Store and .AppleDouble

If you’ve shared your Windows / Unix drives with Mac OS X before, you may notice that Mac OS X will leave some footprints on your shared folders, such as .DS_Store and .AppleDouble. These files and directories are pretty annoying because they showed up in almost every single directory you accessed from the OS X.

There are two ways to solve this computer problem:

  1. Ask Apple to stop generating the .DS_Store
  2. Delete .DS_Store by yourself
  3. Set the shared folder to read-only

Apple had a tutorial on how to stop generating the .DS_Store (See here for details), however this solution requires you to run the command on every single account on every mac.

…If you want to prevent .DS_Store file creation for other users on the same computer, log in to each user account and perform the steps above…

In the other words, you will need to run the command for (# of user on each mac) x (# of mac) times!

For example, if you have 5 users on each mac, and you have 4 macs. You will need to run the command for 5 x 4 = 20 times! Also, I’ve tried this method before and the problem seemed coming back after the upgrading the system (e.g., from OS X 10.7 to 10.7.1). Therefore I decide to go with the second solution: Delete .DS_Store by myself.

How to delete .DS_Store and .AppleDouble automatically

Depending on what operating system the shared drives locate, there are two different ways to solve this problem, and they are very similar.

Situation 1: The shared folder is on Windows

If the shared folder located on a Windows machine, you may want to delete .DS_Store and .AppleDouble from the OS X. First, go to Terminal first:

Create a script

nano clean.sh

Now you are in a text editor. Copy and paste the following into the editor:

find . -name ".DS_Store"        -exec rm -Rf {} \;
find . -name ".apdisk"          -exec rm -Rf {} \;
find . -name ".AppleDouble"     -exec rm -Rf {} \;
find . -name ".AppleDB"         -exec rm -Rf {} \;
find . -name "afpd.core"        -exec rm -Rf {} \;
find . -name ".TemporaryItems"  -exec rm -Rf {} \;
find . -name "__MACOSX"         -exec rm -Rf {} \;
find . -name "._*"              -exec rm -Rf {} \;

Save the file. Don’t forget that we need to make it executable.

chmod a+x clean.sh

Now you can run the script:

./clean.sh

Unfortunately, OS X will recreate these files again after the files are removed. Therefore, I create a cron job to remove them automatically:

sudo nano /etc/crontab

and put the following:

@hourly       root /path.to/script.sh

This will tell the system to run the script hourly.

Of course, you can change it to daily, weekly, monthly etc.

Situation 2: The shared folder is on OS X or Unix

The idea is very similar. You can do the same thing except that the script will be on the server side.

Or you can simply make the shared folder to read-only. Then Mac OS X can not create any annoying files. Here is an example on how to set up a read-only shared drive on Samba:

[Public]
        browseable = yes
        writeable = no
        path = /public
        force directory mode = 777
        force create mode = 777
        comment = This is a public directory
        create mode = 777
        directory mode = 777
        available = yes

Now you can say goodbye to .DS_Store and .AppleDouble.

–Derrick

Our sponsors:

4 Replies to “How to remove .DS_Store and .AppleDouble”

  1. Taro Yamada

    http://support.apple.com/kb/HT1629

    This is an advanced article that contains information about preventing .DS_Store file creation over network connections.

    To configure a Mac OS X user account so that .DS_Store files are not created when interacting with a remote file server using the Finder, follow the steps below:

    Note: This will affect the user’s interactions with SMB/CIFS, AFP, NFS, and WebDAV servers.

    Open Terminal.
    Execute this command:
    defaults write com.apple.desktopservices DSDontWriteNetworkStores true
    Either restart the computer or log out and back in to the user account.
    If you want to prevent .DS_Store file creation for other users on the same computer, log in to each user account and perform the steps above—or distribute a copy of the newly modified com.apple.desktopservices.plist file to the ~/Library/Preferences folder of other user accounts.

    Additional Information
    These steps do not prevent the Finder from creating .DS_Store files on the local volume, and these steps do not prevent previously existing .DS_Store files from being copied to the remote file server.

    Disabling the creation of .DS_Store files on remote file servers can cause unexpected behavior in the Finder (click here for one example).

    Reply
    • Derrick Post author

      Hi Taro,

      Thanks for the solution. I tried that before but it didn’t prevent the OS X from creating the file. Also, this solution requires to run the command on each user account on each mac (i.e., I need to run the command for # of user on each mac x # of mac times. That’s why I decide to do the clean up at the server side rather than client side.

      Thanks again for your link. 🙂

      –Derrick

      Reply
  2. Pingback: “linux delete appledouble ds_store files” Code Answer – My Blog

Leave a Reply

Your email address will not be published. Required fields are marked *