OSX deleting those pesky DS_Store files

Share on:

If you have a MAC and you have ever transferred anything to USB, then opened the USB Drive on a Linux/Windows machine, you would have noticed the creation of .DS_Store files along with whatever the contents you placed onto the USB.

The .DS_Store files are actually used by OSX to store custom attributes of the folder and the DS_Store is actually an abbreviation, which stands for Desktop Services Store. Anyway, more to the point, how do I get rid of these pesky files. Well the easiest way to do it, is to use the cli and the find command. The syntax to recursively delete these files once you have switched into the correct directory is:

1# Change into the USB Directory
2cd /Volumes/USB_DIR
3find . -type f -name '*.DS_Store' -ls -delete

I actually have created a bash alias so I don’t have to remember the whole command and placed it into my .bash_profile file under my home directory, the alias I use is:

1alias cleanDS="find . -type f -name '*.DS_Store' -ls -delete"

A great post that explains the bash_profile file can be found here: http://www.joshstaiger.org/archives/2005/07/bash_profile_vs.html