Home » Questions » Computers [ Ask a new question ]

GNU find with -exec rm removes matches, then complains they don't exist

GNU find with -exec rm removes matches, then complains they don't exist

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

Asked by: Guest | Views: 52
Total answers/comments: 1
Guest [Entry]

"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"