The Eclectic Light Company

Explainer: .DS_Store files

Inside pretty well every folder that you’ve ever opened is a hidden file, one which even showing hidden files doesn’t reveal: .DS_Store. As with other under-the-hood features which Apple really doesn’t want you to know about, you’ll only come across it when it causes trouble.

Over the years, all these .DS_Store files have caused plenty of trouble too. At one stage Apple even recommended that they should be explicitly excluded from servers used for network backups or other storage. They can trip up revision control systems, baffle those who open archives created on a Mac, stop folder copying, and cause errors in third-party backup software, which is the spur to this article.

Since I started developing for Apple Silicon Macs, I’ve been working on some projects like AsmAttic exclusively on them, and copying back my project folders over AirDrop. Ever so often, after I’ve updated a project folder, ChronoSync, one of the three backup apps I use, has complained intermittently when it has tried to back those folders up. That’s because they contain older .DS_Store fies than the ones already backed up, because AirDrop is kind enough to copy .DS_Store files.

The solution to this, as with so many other problems with .DS_Stores, is to open the folder containing that hidden file, move some of its contents about to force it to be refreshed, and move on.

You can’t trash these files in the Finder. Since Sierra, even though you might enable hidden files to be shown in the Finder (Command-Shift-. is a convenient shortcut which I use often), .DS_Store files are so secret that you can’t even unhide them without resorting to Terminal. And I’m sure that it’s only a matter of time before they seemingly vanish from there too.

Trashing them only buys you time anyway: before you can say Jack Robinson, the Finder will recreate them, just to annoy. So what good are they?

.DS_Store files are Desktop Services Stores, containing that folder’s custom attributes, things like icon positions, and in more recent versions of macOS custom settings for the display of file metadata. Among the most important for some users are Finder or Spotlight Comments, which are normally displayed in the Comments section of the Get Info dialog for a file. Those comments may also be duplicated in the com.apple.metadata:kMDItemFinderComment extended attribute (xattr) of that file, but that’s a secondary copy which can fall out of sync with what’s stored in the .DS_Store file, and the Finder ignores the xattr anyway.

The file format was last reversed about five years ago, since when it has undoubtedly changed. Unless you’re insatiably curious, knowing what’s there isn’t exactly useful.

In the past, .DS_Store files have been suspected of leaking data, and were involved in at least one vulnerability. Thankfully they now seem as puzzling and opaque to the developers of malware as they are to other users, but I’m sure that one day, someone else will try to do bad things with them again.

Sometimes they’re confused with another annoying but more useful hidden file: shadow files whose names start with ._ which are used to carry extended attribute data as part of the AppleDouble file format used on some FAT file systems. They too are invisible in the Finder even when hidden files are supposed to be displayed, but are associated with individual files rather than folders.

So in summary they’re invisible hidden files which you’re not supposed to know about. You can’t do much about them, so when they do trip something up, be prepared to massage the folder until its .DS_Store behaves again.

Postscript

Thanks to Mikey @0xmachos for pointing out his simple solution for eradicating .DS_Store files from Git. I’m also very grateful to the flood of useful suggestions in the comments here: if you normally skip the comments, you should browse them carefully below. Sadly, no one seems to have found the ultimate solution, which would be for Apple to change the way that the Finder stores these data. Maybe one day …