Recursively Delete .svn Directories
Version control systems are hugely important when it comes to development of all kinds. I'm a huge fan of git but sometimes I'm required to use SVN. Unfortunately I tend to forget to remove .svn folders when I copy and paste from a directory structure template. This, of course, leads to me overwriting files and results in mass confusion. I recently stumbled up an awesome command line script which recursively removes .svn directories from parent directories.
find . -type d -name .svn -exec rm -rf {} \;
The script starts within the current directory, so be sure you navigate to the directory you want to start searching from first. This script would work on any search type; simply replace ".svn" with the search of your choosing but be careful: if your search term is too general, you may end up deleting a bunch of stuff you don't want to!
![Welcome to My New Office]()
My first professional web development was at a small print shop where I sat in a windowless cubical all day. I suffered that boxed in environment for almost five years before I was able to find a remote job where I worked from home. The first...
![CSS 3D Folding Animation]()
Google Plus provides loads of inspiration for front-end developers, especially when it comes to the CSS and JavaScript wonders they create. Last year I duplicated their incredible PhotoStack effect with both MooTools and pure CSS; this time I'm going to duplicate...
![Digg-Style Dynamic Share Widget Using MooTools]()
I've always seen Digg as a very progressive website. Digg uses experimental, ajaxified methods for comments and mission-critical functions. One nice touch Digg has added to their website is their hover share widget. Here's how to implement that functionality on your site...
![Unicode CSS Classes]()
CSS class name structure and consistency is really important; some developers camelcase classnames, others use dashes, and others use underscores. One thing I've learned when toying around by HTML and CSS class names is that you can actually use unicode symbols and icons as classnames.
IMHO its better to use
find . -type d -name .svn -exec rm -rf {} +
since it saves system resources. And IFAIK all todays bash support + operator.
Does bash really matter here? I thought the + operator was just an option of the latest find versions.
Here’s a registry file to add the same to a windows folder right-click that comes in handy now and then;
(Code highlight that! lol)
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Folder\shell\DeleteSVN\command]
@="cmd.exe /c \"TITLE Removing SVN Folders in %1 && COLOR 9A && FOR /r \"%1\" %%f IN (.svn) DO RD /s /q \"%%f\" \""
Awesome Nick! Thank you!
What does
{} \;do?The ‘{}’ references the file being acted upon by ‘-exec’ and ‘\;’ terminates the exec command
You might also consider using the
svn exportcommand; it was made for this.What I came to say – I always copy files from my repository using:
svn export –force RepositoryURL /path/to/target
(–force tells it to continue even if it is overwriting files – e.g. if you’re exporting the latest revision to a directory where the files already exist)
That also guarantees that only version controlled files get exported – for example, if you have a file with sensitive data in your development directory that is not under version control, you won’t accidentally make it world readable. Don’t have to do that more than once before you get very careful about what you publish :(
I have an old backup of a bunch of SVN repos, and the source repos no longer exist, but I have backups I would like to commit into an new GIT repo, so I need to cleanse them of the .svn folders that were created when I checked the code out the first time.
@goyote, {} is a placeholder for the argument to the -exec clause. The main find , obviously enough , just finds the files, and plugs them in to the -exec clause where it finds the {}.
For more refer to the man page ;) (man 1 find). Or on the web @ http://unixhelp.ed.ac.uk/CGI/man-cgi?find
Funnily enough I posted the same sort of article a week ago. From my own testing I discovered adding the -depth flag was useful for preventing error messages like “find: ./.svn: No such file or directory”
@Will – yes it is useful using svn export to get a clean tree but it is potentially possible that a) the svn repository is no longer available or b) you want to ensure you don’t lose any files that are not actually in svn.
I’ve always used this and it works great, but always test before executing the rm command.
find . | grep .svn | xargs rm -rf
You better use -delete parameter of find instead of -exec rm -rf {} \;
like:
find -type d -name .svn -delete
check the man page of find command
Also sounds like you should import from subversion to git.
http://help.github.com/svn-importing/
If only I could use git at work… .. ..
rm -rf `find . -type d -name .svn`This
find...approach has the deficiency that if you have many folders, it may become too large for the command line. Using xargs is an option but what eclipxe proposed: ‘find -type d -name .svn -delete’ is simple, short and effective.I have always used this;
rm -rf `find . -name .svn`http://sheldon.lendrum.co.nz/removing-svn-directories-recursively_386/04/
I’d be inclined to enclose .svn in quotes (or at least escape with \.svn), as the . will match any character (regex). If you’re random enough to have a directory called nsvn, it would also be deleted.
On win7 I just tend to type *.svn in the explorer’s search box and after that
ctrl+A=> delete :)It can be useful to remove sass-cache folders before an initial commit to svn, thanks.