Question

Say I have 3 directories .git, .hg and .svn somewhere in the folder called lol.

How can I find and remove all of these?

The following does so only for the last one (.svn):

$ find lol -type d -name .git -o -name .hg -o -name .svn -delete

E: This could be done with ls too but not without shopt -s globstar (since I'm not doing it with zsh):

$ shopt -s globstar
$ rm -r $(ls -d ceaw/**/.{git,hg,svn})

E2: Another solution woulda been:

$ find lol -type d -name .git -o -name .hg -o -name .svn | xargs rm -rf
Was it helpful?

Solution

Try using the -exec option instead.

find lol -depth -type d \( -name .git -o -name .hg -o -name .svn \) -exec rm -r '{}' \;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top