Subversion’s svn status command shows all the files that have been modified, but if you have scratch files or other garbage lying around in your source tree, svn will list those, too.
It would be useful to have a way to clean up your source tree, removing those files unknown to Subversion.
svn status src | grep '^\?' | cut -c8- | \
while read fn; do echo "$fn"; rm -rf "$fn"; done
The svn status output lists one file per line.
It puts an M as the first character of a line for files that have been modified, an A for newly added (but not yet committed) files, and a question mark for those about which it knows nothing.
We just grep for those lines beginning with a question mark and cut off the leading eight columns of each line of output so that we are left with just the filename on each line.
We read those filenames with a read statement in a while loop.
The echo isn’t strictly necessary, but it’s useful to see what’s being removed, just in case there is a mistake or an error.
You can at least see that it’s gone for good. When we do the remove, we use the -rf options in case the file is a directory, but mostly just to keep the remove quiet.
Problems encountered with permissions and such are squelched by the -f option.
It just removes the file as best as your permissions allow.
We put the reference to the filename in quotes “$fn” in case there are special characters (like spaces) in the filename.