So far I've come up with this:
find . -name 'CVS' -type d -exec rm -rf {} \;
It's worked locally thus far, can anyone see any potential issues? I want this to basically recursively delete 'CVS' directories accidently uploaded on to a server.
Also, how can I make it a script in which I can specify a directory to clean up?
Well, the obvious caveat: It'll delete directories named CVS, regardless of if they're CVS directories or not.
You can turn it into a script fairly easily:
#!/bin/sh
if [ -z "$1" ]; then
echo "Usage: $0 path"
exit 1
fi
find "$1" -name 'CVS' -type d -print0 | xargs -0 rm -Rf
# or find … -exec like you have, if you can't use -print0/xargs -0
# print0/xargs will be slightly faster.
# or find … -exec rm -Rf '{}' + if you have reasonably modern find
If you want to make it safer/more fool-proof, you could do something like this after the first if/fi block (there are several ways to write this):
⋮
case "$1" in
/srv/www* | /home)
true
;;
*)
echo "Sorry, can only clean from /srv/www and /home"
exit 1
;;
esac
⋮
You can make it as fancy as you want (for example, instead of aborting, it could prompt if you really meant to do that). Or you could make it resolve relative paths, so you wouldn't have to always specify a full path (but then again, maybe you want that, to be safer).
A simple way to do would be:
find . -iname CVS -type d | xargs rm -rf
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With