September 07, 2005
Baby Steps

I could get to like this bash thing. I have a fairly deeply nested directory tree. I wanted to delete all directories within that tree with a given name. (.svn, as it happens.) I was trying to use ls to generate a list of directories, but ls -R .svn wasn't giving me anything.

So, I joined the #bash channel on freenode, and was steered in the right direction in seconds - use the find command. Here's the end result, for my own reference as much as anything:

yes | find . -name '.svn' -exec rm -r {} \;

Beautiful, no? Well, OK, no, but it works.

Posted to Mac by Simon Brunning at September 07, 2005 01:04 PM

I almost always sling some python for stuff like this because it's portable between win/linux.

And as a matter of fact, I have a in my path right now.

Posted by: j on September 7, 2005 02:08 PM

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

will also do the job

Posted by: Matty on September 7, 2005 04:01 PM

Using zsh, you could just do

rm -rf **/.svn

if your directory structure isn't too huge and your operating system doesn't have ridiculously tiny limits on command line length.

Posted by: Doug L. on September 7, 2005 05:58 PM

I use xargs rather than find's -exec argument:

find . -name '.svn' | xargs rm -rf

You can use xargs on any list of file names. For example, to list the contents of files containing the string 'python':

find . | xargs grep -l 'python' | xargs cat

Anyway, you can most assuredly see Perl's TIMTOWTDI heritage in bash...

Posted by: Alan Green on September 8, 2005 05:13 AM

On for a different approach, you could look at "svn export":

Posted by: paul on September 8, 2005 08:31 AM

I second the zsh tip.
Bash is for wimps.

Posted by: Darren on September 8, 2005 11:42 AM
Post a comment

Email Address:



Remember info?