Linux & SVN: How to remove all versioned files but KEEP directory structure, ignore .svn dirs?
I want to remove all the versioned files from my repository, but KEEP the versioned directory structure. Obviously I want to leave all the .svn directories untouched.
In other words, I want to completely empty a working copy's directory structure WITHOUT harming the directory structure itself.
For example, removing the files from this structure:
dir/
.svn/
[files]
svsubdir1/
file1
.svn/
[files]
subdir2/
file2
file3
file4
.svn/
[files]
subsubdir1/
file5
.svn/
[files]
Should result in:
dir/
.svn/
[files]
svsubdir1/
.svn/
[files]
subdir2/
.svn/
[files]
subsubdir1/
.svn/
[files]
I'm looking for some sort of find
command or something to accomplish this, and I'm having trouble constructing the command. Thanks for the help!
Solution 1:
find dir/ -path '*/.svn' -prune -o -type f -print
should fit the bill (mostly comes from the find manpage for -path
). Pipe it to less and check it out. What it does is first find (path ends in .svn and don't recurse into (prune) this directory) or (if it's a file, print it).
If it looks good, change it to
find dir/ -path '*/.svn' -prune -o -type f -exec rm {} +
The + version sticks all of the files together into one rm command. If you're paranoid, keep a backup of the tree (cp -a dir/ otherdir/
) first.
Solution 2:
find . -not -path "*/.svn/*" -and -type f -and -exec /bin/rm '{}' \;
Ought to do the trick.