Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't my 'find' work like I expect using -exec?

Tags:

find

shell

unix

I'm trying to remove all the .svn directories from a working directory.

I thought I would just use find and rm like this:

find . -iname .svn -exec 'rm -rf {}' \;

But the result is:

find: rm -rf ./src/.svn: No such file or directory

Obviously the file exists, or find wouldn't find it... What am I missing?

like image 224
Jonathan Adelson Avatar asked Mar 17 '09 16:03

Jonathan Adelson


1 Answers

You shouldn't put the rm -rf {} in single quotes.

As you've quoted it the shell is treating all of the arguments to -exec it as a command rather than a command plus arguments, so it's looking for a file called "rm -rf ./src/.svn" and not finding it.

Try:

find . -iname .svn -exec rm -rf {} \;
like image 54
Dave Webb Avatar answered Oct 19 '22 05:10

Dave Webb