How can I trigger the creation of a .DS_Store file in a directory?

How can I trigger the creation of a .DS_Store file in a directory?

I have a Macbook Pro and at some point I found that within a directory, the modified dates on some of first level subdirectories directories had changed. I looked into it and found that there were .DS_Store files in these directories or some subdirectories of them. There are some things i'm doing to try to get rid of them and restore the modified dates and then ensure it doesn't reoccur (I understand one can set finder to not produce these .DS_Store files). But, aside from that, i'm also trying to reproduce the problem and that's what i'm asking about here.

I have tried creating a directory on my mac, and looking at it in finder, adding a file to it, and viewing it from a windows machine, and copying it from mac to windows, but it's not generating that .DS_Store file

It seems like it happens in sweeps.. a bunch with this date/time, a bunch with that date/time. But I don't know exactly what I was doing at that date/time. So I can't really determine what sets it off. And i'm trying to determine that well enough to reproduce it , to be able to trigger it myself.

I tried copying a directory to a USB with USB formatted as exFAT.

I'm guessing to do it is something to do with copying or viewing in finder or viewing the mac folder from a windows machine and copying things from there.

I just can't seem to reproduce it myself. My test directory is not getting a .DS_Store file in it.

I'd be interested if anybody knows how to reliably reproduce the phenomena of .DS_Store file being generated in a directory or directories.

Any ideas how I can do that?


I would suggest creating a folder from the terminal. Inside the folder create a temporary folder and a temporary file. From the terminal, open the directory in finder, create a new folder, and rearrange all of the items. After messing around, check the terminal to see if .DS_Store is created.

Here are the steps:

  1. Open Terminal
  2. mkdir Folder
  3. cd Folder
  4. mkdir MyFolder
  5. touch MyFile.txt
  6. open .
  7. Menu > Sort By > None
  8. Menu > File > New Folder > "Temp"
  9. Move all the items around
  10. In terminal, check to see if the .DS_Store has been created.

P.S. I am running macOS 11.1


This file persists Finder view and sort metadata so changing the folder view options or then moving an icon in the “desktop” view mode to a different spot should be sufficient to cause .DS_Store to be changed.

The filesystem may cache data, so the file write might not flush up until you eject the share in some cases. For network volumes or internal storage, it should be near instant to write the file unless an edge case exists where the system had the file open and then you delete it. That type of temporary file would be invisible until the delete was committed.

Using the Apple Menu to log out the current user should flush all writes to all reasonable locations of .DS_Store. You can toggle invisible files if you want to see these created.

  • --.