Quick Tip: Removing unwanted .DS_Store Files

.DS_Store files are created by OS X to store information relevant to the Finder, such as window positioning, and Finder comments. For the majority of users they go completely unnoticed because by default they are invisible, as are all other files beginning with a period. The easiest way to see them is to pop open the terminal and type in "ls -la ~". What you’ll see are a list of all the files in your home directory, including the invisible ones.

So why care about the .DS_Store file? They are insignificantly small, hidden, and help the Finder out. That is, unless you’re operating in an environment with PCs, or accessing files from a Mac over and FTP client. Then they can become rather obvious and very confusing.

There are a bunch of little applications that can remove .DS_Store files, among other things, but who wants to download an application for something that can be done with a really simple command. Most of the commands I’ve seen involve find executing rm followed by a few other arguments. For the life of me I can’t understand why people aren’t just using the “-delete” argument in find.

Here is my simplified rendition:
find . -name .DS_Store -delete

Yes folks, it’s that simple. find is a Unix tool for locating files. The period is the path to start at. I could have used “/” if I wanted it to start at the root of the drive. Period means start from my current location in the Terminal (usually represented to left of where you start typing in the Terminal). The “-name” tells find what to look for, in this case the pesky .DS_Store file. Lastly -delete tells find to remove the file when it encounters it. Remember that you might have to use the sudo command depending where you want to remove them from.

A word of caution, this command permanently removes the .DS_Store files. It doesn’t move them to the trash. The Finder will replace the .DS_Store files when it needs to. As with any Unix command, please type carefully and fully understand what is going on, before you hit return. There are no “undos,” that’s why it’s a great idea to backup your computer. While this command, when used right should be harmless, backing up could save you from the mess you get into from someone else’s Unix trick, or enabler. I hope I haven’t scared anyone.

Enjoy.

2 Responses to “Quick Tip: Removing unwanted .DS_Store Files”

  1. Cody says:

    Sorry if this seems to be a late and random reply, but I’m having issues with .ds_store files no one else seems to be having.

    My Mac keeps forcing .ds files into my music folder for files I have not downloaded or bought on it. I had them transferred from a multimedia player, and now each music folder separated by artist contains the same exact .ds store file. Because of this, there is no way to transfer them to other storage devices because the storage that it takes up is nearly doubled, and I cannot delete simply delete them one by one because there are nearly 350 files, and I have no option to delete in numbers from other storage devices, meaning I would have to delete about 350 “._filename” files individually. Not gonna’ happen. Is there any application designed to remove invisible files permanently that are absolutely not necessary?

  2. Scott P. says:

    You can’t really stop them from being created when you go into a folder because the Finder uses that to maintain window positions and other user initiated changes. Using the command from this post will delete them, and as long as you don’t go back into the folders they shouldn’t come back. You can only prevent them from being created on network volumes as far as I know. Also most media players should know to hide files beginning with a “.” as the convention is around 40 years old.