The following command line will remove all of the unversioned files in a subversion sandbox.
svn status | grep ^\? | sed -e 's/^.......\(.*\)$/\1/g' | sed -e 's/\\/\//g' | xargs -Ifile rm -rf file
The call to svn gives us the status of our sandbox. From that we use grep to select the lines that begin with a question mark. Then using sed we strip off the leading seven characters, which svn uses to indicate the status of files. This leaves us with just the file name. Next, we use sed to translate back slash characters to front slash characters. Finally the output, which is now just a list of file or directory names is sent to xargs which calls remove on each of them.
Note that the second call to sed, which substitutes back slashes for front slashes, is due to my use of subversion for Windows in a Cygwin bash shell. It can be safely omitted if your environment does not require it.
Also note that we are making an assumption about the output of svn status that is not 100% correct. Sometimes every line does not refer to a file, nor are there always seven leading characters before a line that does refer to a file. The main place I have noticed this is when there are merge conflicts. Nonetheless, for most cases this assumption is workable.
Finally, a simple variant of this command can be used to copy all of the modified files in one sandbox to another. In that case we would grep on “^M”, which would select the modified files, and then have xargs execute “cp –parents” with an appropriate destination argument.
On the other hand, if you’re on Windows and have Tortoise SVN a “Shift-Right Click” will get you a menu option for doing this.