Live Chat!

Remove all .svn directories at once

* * * * ½ 3 votos

January 19th, 2007 toydi Posted in Common, find, rm, xargs | Hits: 24084 |

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

5 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.

Leave a Reply

Security Code: