On Mac OS X, .DS_Store files seem to contain custom view settings for the directory when it is viewed in Finder (file manager GUI). I want every directory to use my default view settings.
Is this shell command safe to delete all of them (that I have permission to) from the drive? i.e. no chance or false positives or other mishaps.
cd /
find . -name .DS_Store -print0 2>/dev/null | xargs -0 -p rm
None of the answers given so far have addressed the safety issue and I can't comprehensively, either. However, I can say that the command you show will work as you intend (plus you have the extra safety of being prompted before each file is removed).
I would add
-type f
for a little extra safety.The disadvantage of the other answers is that they're either don't prompt to continue, slow (but prompting for permission makes this moot), would fail if there is a large number of files to delete (exceeding command line length maximum) or would fail if there were spaces in the filename (which does not apply in this case).
Here is another form for completeness:
It prompts for confirmation. It would be about the same speed as the
xargs
version (except that it's prompting for each file). It would handle filenames with spaces if that were applicable. It will handle any number of files.Why not just use
find
for the whole thing?find / -name .DS_Store -delete