Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
share|improve this question
up vote 6 down vote accepted

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:

find / -name .DS_Store -type f -exec rm -i {} +

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.

share|improve this answer
rm won't delete directories without -r – Nerdling Jul 21 '10 at 13:55
@Nerdling: It was my understanding that it was only files that were to be deleted (hence the type -f, also). .DS_Store is a file, not a directory, correct? – Dennis Williamson Jul 21 '10 at 21:13
They are just files, so type -f is rather useless here. – Nerdling Jul 22 '10 at 0:36
Still; the OP was looking to avoid false positives so why not? – Duane Jul 22 '10 at 3:00

Why not just use find for the whole thing?

find / -name .DS_Store -delete

share|improve this answer
Why not How about just using find . -name .DS_Store -delete? – Zoredache Jul 21 '10 at 16:54
Yes, why not? :-) – Nerdling Jul 22 '10 at 0:36

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.