0

I'm on macOS Sierra. I'd really love to know how to use terminal to set the date modified of all .DS_Store files in a specific hierarchy to a given date.

So far, I know that I can do this:

sudo touch -t 200001010101 ./.DS_Store

That will set the date modified of the .DS_Store file in the current directory to 01/01/2000 01:01 AM. But I need to find a way to do this not just for the current directory, but all subfolders within that directory as well.

I seriously hope there is a simple solution for this. I'm sick to death of the date modified of various folders on my system being changed simply because of view changes I make in Finder when browsing them!

This question is about a smaller part of a larger task I'm trying to accomplish. I've almost got it all working now except part of the script that only seems to work when I run it from terminal directly. Here's a link to the main issue in case anyone reading this might be able to help: Service to execute series of commands on selected folders to eliminate issues with .DS_Store files in Finder

1 Answer 1

1

If you use bash you can try something like:

sudo touch -t 200001010101 **/.DS_Store

This command will change the timestamp of .DS_Store in all subdirectories

More universal way is to use command like:

find . -name .DS_Store -type -f -exec touch -t 200001010101 {} \;

P.S. You may need to set this shopt -s dotglob if it's not already set.

3
  • Is there any way to make this recursive to all subdirectories within the current directory? After executing this command, I noticed that the .DS_Store files in subdirectories deeper than the directories within the current directory still retained their current modification date.
    – MikMak
    Jul 20, 2022 at 12:57
  • @MikMak, check my edited answer Jul 20, 2022 at 13:01
  • 1
    For bash, you would need to do a shopt -s dotglob to make ** work. In zsh, the command would run like this without the need to set something. Jul 25, 2022 at 8:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .