SVN code snippet: Moving all unversioned files to a different location

We have recently been moving a lot of sites from some legacy servers onto the really rather fine Rackspace Cloud. Some of the sites are pretty big and sprawling, and a number of people have worked on them over the years.

We use Subversion to manage our code, which makes things a heck of a lot easier and more robust but even so it can occasionally be tricky to see which files in a directory need to be migrated and which can just be archived. This little code snippet came in handy when I needed to quickly clear all the unversioned files out of a directory to check that they really weren’t needed for the running of the site:

svn status | grep '^?[:space:]*.*\..*' | mv `sed 's/^?[ \t]*//'` /temp-store-for-unversioned-files/

The grep is specifically designed to only catch files with a file extension (e.g. .sql, .txt, etc.) so you may need to tweak that to fit you needs – here’s a simple reference on using regular expressions with grep.

Hope it comes in handy for someone else out there too!