[lug] Removing hidden directory recursively

Hugh Brown hugh at math.byu.edu
Tue Apr 25 20:12:53 MDT 2006


On Tue, 2006-04-25 at 18:03 -0600, John-David Childs wrote:
> On 4/21/06, Hugh Brown <hugh at math.byu.edu> wrote:
>         
>         find . -type d -name .svn -exec echo {} \;
>         
>         to make sure you aren't getting something you didn't intend
>         and then
>         
>         find . -type d -name .svn -exec rm -rf {} \;
> 
> Nuh-uh...this will remove any directory containing a .svn extenion AND
> ALL FILES in all subdirectories, regardless of .svn extension! 
> 
> What you want is this:
> 
> find . -type f -name "*.svn" -exec rm -f {} \; && find . -type d
> -empty -exec rmdir {} \;
> 
> This will remove all files with an .svn extension and remove any empty
> directories afterwards. 


Actually, I don't believe that's the case.  In order to meet the find
requirements, it has to be a directory and the its name must be .svn.
Nothing more or less.

e.g. with

dir.svn/file
.svn/file
.svn/dir/file
testdir/file.svn

and then running "find . -type d -name .svn -exec echo {} \;"  the
output is:

.svn


So running "find . -type d -name .svn -exec rm -rf {} \; "
will leave you with

dir.svn/file
testdir/file.svn

It's been a while since I played with a subversion checkout, but my
memory says that every directory in the checkout has a .svn directory in
it and the only contents of the .svn directory are related to the
checkout and do not contain files.  Technically someone could decide to
squirrel data into the .svn/ dir and the find I suggested would nuke it.
But ultimately, I believe the requirements were to remove all
directories named exactly .svn as well as their contents.

You also notice that the first command given would echo everything that
matched so that if there was something amiss it could be caught.

Hugh





More information about the LUG mailing list