Remove all .svn directories at once

January 19th, 2007 toydi Posted in Common, find, rm, xargs | Hits: 68160 | 8 Comments »

When you check out a project code base from a svn repository, each downloaded directory (from top to the deepest) contains a .svn hidden directory that keeps svn’s necessary metadata.

If you want to remove them all at once, here’s one way to do it:

 ~/project_dir $> find -name .svn -print0 | xargs -0 rm -rf

find -name .svn searches the current directory hierarchy for files named .svn.

-print0 ensures each filename ended with a null character. This allows filenames that contain newlines/whitespaces to be interpreted correctly by programs that consume the output.

xargs -0 rm -rf receives the output and passes it to rm for file removal. Remember to use -0 option when the input items are terminated by a null character.

Update: Thanks to geek00L, actually find alone is sufficient:

find /project_dir -type d -name .svn -exec rm -rf '{}' +

Update: svn export should be the right tool that does the job (thanks to aizatto):

svn export project_dir new_dir

8 Responses to “Remove all .svn directories at once”

  1. how about this -

    find /whateverdirectory -type d -name '/svn' -exec rm -rf '{}'\;

    Remember to change file type to fit your need. However xargs more faster when searching globally in the system, but I assume if you already know which directory consist the files as you mention so using -exec should be enough.

    Cheers

  2. Should just use the svn export feature…

    
    svn export http://svn.example.com/trunk
    
  3. [...] At one time I had a tarred site still containing all its .svn directories. Needing to just start over and remove all .svn directories, I found the answer at Linux by Examples under the posting/page “Remove All .svn Directories at Once“. [...]

  4. svn export might be good, but the example cater for those machines without svn installed.

  5. The other thing about svn export is that it will only function if the top directory on which it is executed is actually an svn repository or working copy. If you’ve got .svn directories scattered throughout a file hierarchy but they don’t belong to a cohesive svn working copy then svn export wont cut it.

  6. Currently its good time to create a few plans for the longer term and it is the moment to take a break. I have learn this post and if I may just I wish to recommend you few interesting issues or advice. Maybe you can post subsequent articles referring to this blogpost. I hope to study more issues of it!

  7. [...] and bash lines which help in the daily business as a developer. Imagine a life without “Remove all .svn directories from a path“, “Find duplicate files and remove them“ or “Watermark a PDF file”. [...]

  8. SVN export is what you need. Open the SVN clien your using (your IDE for instance). In the NetBeans for instance you can find export in the menu Team -> Export… (when you’re already connected to the repository). If for some reason you do not have access to the repository, you may use tools like http://sourceforge.net/p/svncleaner/wiki/Home/ to remove the hidden .svn folders.

Leave a Reply