I was recently doing some early spring cleaning on my NAS and external hard drives, and while doing so, came across .DS_Store files in every directory. While not a gamechanger for my cleaning, I wanted to also to clean them up as well.

But first, what is a .DS_Store file and what’s it used for? Well, according to Apple:

“Your Mac determines how each window and its contents should appear by collecting file information such as labels, tags, and other forms of metadata.

“In macOS Sierra 10.12 and earlier, your Mac gathers all metadata for the files in a folder, compares it to the folder’s .DS_Store file, and then displays the folder’s contents. In macOS High Sierra 10.13 and later, this behavior is changed slightly: If a folder is sorted alphanumerically, the contents are displayed immediately, then the Finder collects and compares the rest of the folder’s metadata.”

So, not entirely necessary to be sitting in every directory on my NAS that my MacBook has touched.

Disable Writing .DS_Store Files on Network Shares

One thing to keep in mind is that it’s not much use deleting these files if they are just going to reappear the next time you open a folder. So first, run the following command:

defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool TRUE

To revert this, change the boolean TRUE to FALSE.

Removing .DS_Store Files Recursively

Move to the directory where your .DS_Store files are:

cd /Volumes/your directory

Connected NAS folders are mounted in MacOS under /Volumes

Recursively delete the files with:

find . -name '.DS_Store' -type f -delete

This will find and delete all .DS_Store files within that directory, and all subdirectories within the directory.

Bonus: Remove desktop.ini Files

If you have accessed your NAS with Windows, and see a load of desktop.ini files, they are basically the Windows version of those .DS_Store files. You can delete them as well with:

find . -name 'desktop.ini' -type f -delete