Remove all .svn directories at once
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
Live Chat!









January 19th, 2007 at 7:25 pm
how about this -
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
January 24th, 2007 at 9:37 am
Should just use the svn export feature…
March 7th, 2007 at 10:06 am
[...] 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“. [...]
July 19th, 2007 at 5:24 pm
svn export might be good, but the example cater for those machines without svn installed.
December 19th, 2008 at 9:26 am
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.