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!
With CSS border-radius, I showed you how CSS can bridge the gap between design and development by adding rounded corners to elements. CSS gradients are another step in that direction. Now that CSS gradients are supported in Internet Explorer 8+, Firefox, Safari, and Chrome...
I get asked loads of questions every day but I'm always surprised that they're rarely questions about code or even tech -- many of the questions I get are more about non-dev stuff like what my office is like, what software I use, and oftentimes...
A little over a year ago I authored a post titled Fancy FAQs with MooTools Sliders. My post detailed a method of taking boring FAQs and making them more robust using the world's best JavaScript framework: MooTools. I've taken some time to...
It's something that makes all men live in fear, and are often uncertain of. It's never spoken, but the curiosity is always there. Nine out of ten women agree in the affirmative. Advertisers do their best to make us feel inadequate but...
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 export
command; 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.