I am trying to run a single command to change all .DS_Store files within a directory and all subdirectories recursively.
So far, I have been using the following commands to find the files, set their date modified to Jan 1 01:01:01 2001, and then to find them and set their permissions to read only for user, group, and everyone .
find . -name '.DS_Store' -print0 | xargs -0 sudo touch -t 200101010101
find . -name '.DS_Store' -print0 | xargs -0 sudo chmod 444
I'm guessing there is a more efficient way to do this with a single command, but I'm not sure how to use the output of the find command in more than a single following command.
Ideally, if there is any error/failure encountered with any of the files/commands, I would want to have the command line stop and output the error message rather than continuing to execute. I've seen elsewhere that using && to separate commands on a single line would do this, but am not sure how to use this in conjunction with the output from the find command.
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 here might be able to help: Service to execute series of commands on selected folders to eliminate issues with .DS_Store files in Finder