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!

link|improve this question

58% accept rate
The reason I'm doing this is that I have a web app which has been developed in "versions" but has never been under revision control before. I want to put it under SVN revision control now, and for ease of historical reference, etc., I'm trying to replicate a progression of four versions from four different "backup" folders containing progressively older versions. Once the files are deleted, I can copy the newer files into the hierarchy to simulate the newer revision. Not sure if all that makes sense. :) – Brian Lacy Oct 26 '10 at 19:59
feedback

2 Answers

up vote 5 down vote accepted
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.

link|improve this answer
Perfect solution, that's exactly what I needed! Thanks Derf! – Brian Lacy Oct 26 '10 at 19:53
In place of '-exec rm {} +' you can also use the more intuitive '-delete' option. – Tim Bielawa Oct 26 '10 at 21:05
@Tim According to the find manpage, -delete is depth-first and therefore conflicts with -prune because the files inside the folder would be checked before the folder itself was examined. The other solution (using -not -path ... rather than -path ... -prune can use the -delete option. – DerfK Oct 26 '10 at 21:56
Nice catch! – Tim Bielawa Oct 26 '10 at 22:05
feedback
find . -not -path "*/.svn/*" -and -type f -and -exec /bin/rm '{}' \;

Ought to do the trick.

link|improve this answer
Just a tip, but instead of -exec /bin/rm '{}' you can use -delete. – Aaron Copley Oct 26 '10 at 20:15
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.