Clean SVN Meta-Data From Project Via Commandline in *Nix

I just ran into a situation that I dont think I have faced before and I thought I would post the solution to the problem for my own future reference and for those of you that may find it useful.

I use CFEclipse and Subversion for working with my projects, but tonight I wanted to copy the contents of one of my project folders into another project folder using the Finder in OS X. So good ‘ole drag-n-drop and I was done. What I didnt take into account was the fact that you cant see all of the “.svn” folders in Finder by default since they are hidden, so all of them were copied into the new projects folder.
Well to say the least I wanted to clean all of that stuff out before I shared the new project folder to an SVN repository. So I opened terminal and had to think of a way to recursively delete the “.svn” folders under every folder in the application. There were 27 instances nested in the application so I didnt want to do each one by hand.
So a bit of Googling and I turned up a neat trick about the ‘rm’ commandline tool that I never knew.
First I wanted to find how many .svn folders I was dealing with so I typed this in the terminal:

find . -type d -name .svn

Which produced a long list of every instance. So it turns out that you can pass that find command to ‘rm’ as an argument and it will delete every instance that is found. It looks something like this:

rm -rf `find . -type d -name .svn`

Notice that the find command is wrapped in those funny grave accent quotes (key to left of ‘1’).
Now I know there is probably a better/faster way to do this with ANT but I dont have ant build files setup for every project. So I just thought that this might be useful.

4 thoughts on “Clean SVN Meta-Data From Project Via Commandline in *Nix”

  1. If you use the SVN ‘export’ command it will copy the files without the .svn directories.

    Also if you do any of the file/sync tasks using ANT I think it will automatically filter out those directories as well.

  2. Hi Russ,

    shell scripting is pretty powerful, I have the following that I use:
    #!/bin/sh
    dirsfound=`find . -name ".svn"`
    for i in $dirsfound
    do
    echo Deleting $i …
    rm -Rfv $i
    done

    You can also actually pipe the find command to the rm: find …. | rm -Rf

Leave a Reply

Your email address will not be published. Required fields are marked *


*