4

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.

4 Answers 4

3

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.

1

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

1

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
0

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.

You must log in to answer this question.

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