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!
Before we get started, it's worth me spending a brief moment introducing myself to you. My name is Mark (or @integralist if Twitter happens to be your communication tool of choice) and I currently work for BBC News in London England as a principal engineer/tech...
With Firefox OS, asm.js, and the push for browser performance improvements, canvas and WebGL technologies are opening a world of possibilities. I featured 9 Mind-Blowing Canvas Demos and then took it up a level with 9 Mind-Blowing WebGL Demos, but I want to outdo...
The jQuery homepage has a pretty suave tooltip-like effect as seen below:
Here's how to accomplish this same effect using Dojo.
The XHTML
The above HTML was taken directly from the jQuery homepage -- no changes.
The CSS
The above CSS has been slightly modified to match the CSS rules already...
I was inspired when I first saw Addy Osmani's original ShineTime blog post. The hover sheen effect is simple but awesome. When I started my blog redesign, I really wanted to use a sheen effect with my logo. Using two HTML elements and...
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.