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: