Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

theawesomesite.com
0.2.v.theawesomesite.com
0.3.v.theawesomesite.com

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 "*.v.theawesomesite.com" -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 stackoverflow.com Jan 10 '10 at 8:15

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

add comment

4 Answers 4

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
add comment

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

share|improve this answer
add comment

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 *.v.theawesomesite.com
    [[ $dir == 0.3.v.theawesomesite.com ]] || rm -r $dir
done

Or:

echo *.v.theawesomesite.com | grep -v '^0.3.v.theawesomesite.com$' | xargs rm -r

Or even:

mv 0.3.v.theawesomesite.com 0.3.v.theawesomesite.com.SAVED
rm -r *.v.theawesomesite.com
mv 0.3.v.theawesomesite.com.SAVED 0.3.v.theawesomesite.com
share|improve this answer
add comment

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 0.2.v.theawesomesite.com 0.2.v.theawesomesite.com/file1 ...

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

share|improve this answer
add comment

Your Answer

 
discard

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.