What are exactly .DS_Store and ._.DS_Store?
.DS_Store
If you have ever used Git on a macOS system, you may have already noticed that .DS_Store is always present in your .gitignore files. But what exactly is a .DS_Store file, and why does macOS create it?
In macOS, .DS_Store, short for Apple Desktop Services Store, is a file that stores custom attributes of its containing folder,such as folder view options, icon positions, and other visual metadata information.
Let me help you understand this with an example.
Using CLI (important!), create a folder named dsstore with following structure (the two TXT files can contain any content):
~/Playground/dsstore
❯ tree -a
.
├── a.txt
└── sub
└── b.txt
2 directories, 2 files
You can see that there is no .DS_Store file.
Now open the sub folder in Finder and change its ordering (for example, by Date Modified).
Then check the folder structure again using tree:
~/Playground/dsstore
❯ tree -a
.
├── .DS_Store
├── a.txt
└── sub
└── b.txt
2 directories, 3 files
A .DS_Store file is created in its parent folder to store the visual settings of the sub folder.
Note that opening the sub folder and changing its ordering did not cause Finder to create the .DS_Store file within it;
rather, it created in its parent folder.
._.DS_Store
But what about ._.DS_Store? Let's do another experiment using Linux SMB.
Same as before, create a folder named dsstore with following structure using CLI:
alaneuler@debian ~/playground/dsstore
❯ tree -a
.
├── a.txt
└── sub
└── b.txt
2 directories, 2 files
Mount the SMB share then open the sub folder in Finder and change its ordering.
Check the folder structure again:
alaneuler@debian ~/playground/dsstore
❯ tree -a
.
├── a.txt
├── ._.DS_Store
├── .DS_Store
└── sub
└── b.txt
2 directories, 4 files
Beside the expected .DS_Store file, an additional ._.DS_Store file is created. It is AppleDouble encoded Macintosh file.
It is created on file systems such as SMB and NFS that do not natively support extended attributes, or Finder information.
It stores the extra meta-data alongside the original file with name prefixed with ._.
Finder needs to store some extra information for the .DS_Store file, so it creates the ._.DS_Store file.
We can try further, add some comments for file a.txt in Finder (see Appendices), then we can see:
alaneuler@debian ~/playground/dsstore
❯ tree -a
.
├── ._a.txt
├── a.txt
├── ._.DS_Store
├── .DS_Store
└── sub
└── b.txt
2 directories, 5 files
A new file ._a.txt is created to store the extra meta-data (file comments) for a.txt!
Appendices
