WP-Mix

A fresh mix of code snippets and tutorials

Remove .DS_Store in macOS

I would give my left testicle to stop macOS from creating .DS_Store files in every freaking directory on the system. The stupid files have been driving Mac users mad for years, and apparently there is no end in sight. Fortunately, there are a couple of ways to remove them.

Note: use these techniques at your own risk! View references

Remove .DS_Store via Terminal

If your command line skills are strong, and you trust the results, here is simple command that you can run to recursively remove ALL .DS_Store files from your machine. Important: make sure you have a complete backup of your system before running this command, just in case.

sudo find / -name ".DS_Store" -depth -exec rm {} \;

To do the same thing for a specific directory only, navigate to the directory and then run this command:

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

Note that these techniques only remove existing .DS_Store files; new .DS_Store files will be created as macOS continues to do its crazy DS-adding thing. It’s a nice temporary fix though.

Remove .DS_Store via app

My new favorite utility app is Dot Cleaner. Dot Cleaner says what it does and does what it says. Super simple way to recursively remove all .DS_Store files from any specified directory. Simply select your directory, click the “Start Cleanup” button, and done.

Of course, as with all other currently know DS-removal techniques, the .DS_Store files eventually will be recreated by macOS. That’s why the title of this post begins with “Remove” instead of “Disable” — it’s just not possible to permanently disable the DS files using non-hacky methods.

Bonus! Disable .DS_Store on external drives

Amazingly, it is possible to disable the creation of .DS_Store files on external volumes. To do so, open Terminal and enter the following command:

defaults write com.apple.desktopservices DSDontWriteNetworkStores true

Note that you may need to log out and/or restart your machine after executing this command. Source provided below.

References