Super User is a question and answer site for computer enthusiasts and power users. 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

I have a /domains directory in which I have entries such as

And after testing 0.3, I'll set the main domain to alias the new version. Works really nice. Now, I want to be able to delete all old versions. I tried this:

find /domains -name "*" -not -name "0.3.v.*" -ignore_readdir_race -exec rm -fr {} \;

The old domain directories are deleted, but for each of them find complains No such file or directory. I added the -ignore_readdir_race under the idea it would help, but it has not.

Any ideas how to get rid of these complaints and why find is complaining in the first place. It has to be stating after the -exec but I can't figure out why.

share|improve this question

migrated from Jan 10 '10 at 8:15

This question came from our site for professional and enthusiast programmers.

Try adding the -depth flag, to process each directory's contents prior to the directory itself.

EDIT by Asker: Or, the -prune flag, as I don't care about the contents at all. Your suggestion made me think about it searching in the directories after deleting them, which I didn't consider, and gave me the end answer, so I wanted to make this the correct answer I actually used.

share|improve this answer

You could use -delete action instead of -exec (as long as you have recent find).

share|improve this answer

Find is best saved for when you need to recurse directories, which it doesn't look like you do. In this case, I would just do some shell magic. Options include:

for dir in *
    [[ $dir == ]] || rm -r $dir


echo * | grep -v '^$' | xargs rm -r

Or even:

rm -r *
share|improve this answer

Try using single-quotes instead of double-quotes.

The shell expands double-quotes before passing them to find, so it may be rm'ing the directory before the files:

find /domains -name ...

So it may process the directory first, then look for the files that it just deleted.

share|improve this answer

You must log in to answer this question.

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