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!
![How to Create a RetroPie on Raspberry Pi – Graphical Guide]()
Today we get to play amazing games on our super powered game consoles, PCs, VR headsets, and even mobile devices. While I enjoy playing new games these days, I do long for the retro gaming systems I had when I was a kid: the original Nintendo...
![Designing for Simplicity]()
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...
![Highlight Table Rows, Columns, and Cells Using MooTools 1.2.3]()
Row highlighting and individual cell highlighting in tables is pretty simple in every browser that supports :hover on all elements (basically everything except IE6). Column highlighting is a bit more difficult. Luckily MooTools 1.2.3 makes the process easy.
The XHTML
A normal table. The cells...
![From Webcam to Animated GIF: the Secret Behind chat.meatspac.es!]()
My team mate Edna Piranha is not only an awesome hacker; she's also a fantastic philosopher! Communication and online interactions is a subject that has kept her mind busy for a long time, and it has also resulted in a bunch of interesting experimental projects...
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.