Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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!

share|improve this question
    
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
add comment

2 Answers

up vote 9 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.

share|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
add comment
find . -not -path "*/.svn/*" -and -type f -and -exec /bin/rm '{}' \;

Ought to do the trick.

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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