How to recursively remove .svn directories

July 23, 2009 | Linux, Mac, Subversion, Time Savers, Windows | 19 comments

Regular readers may have clocked onto the fact that I use Subversion. Well the way it works it to keep a hidden set of directories within your checked out repository. It uses this to track any changes etc.. Each directory is called ‘.svn’ and is within each and every directory and subdirectory you have.

The problem

Now I know I am not alone in saying that when you want to upload the files to a remote server you have to do one of two things

  • Upload the files and .svn directories to your server which is likely to take twice the time and twice the disk space
  • Make a separate local copy of your files and then remove the .svn directories one by one.

I prefer to take option two although in recent months I have taken on the former through sheer laziness. I decided to look for a solution and found my answer…

The answer

For windows machines you need to create a secondary copy of your files to upload, this means it won’t wipe out your local repository files (the ones you want to keep). Next, create a ‘.bat’ file (batch file for executable scripts). The simplest way to do this is to open notepad and doing File > Save as > remove_svn.bat after copying in the code below. It needs to be saved in the root directory of your repository copy. This is important if not it will recurse all directories below the one it is placed in.

for /f "tokens=* delims=" %%i in ('dir /s /b /a:d *svn') do (
  rd /s /q "%%i"

I have done all the hard work for you on this one.
Just click the following link:

For Macs and other Unix based machines you need to do something similar. This time we simply run a command on the shell (or create a shell script out of it). Again this must be placed in the directory you want to recurse through.

find . -name .svn -print0 | xargs -0 rm -rf

The Credit

Credit for these snippets goes to the following sites. Whether they were the original authors or not I don’t know but credit where credit is due etc..

Mac version –
Windows Version –

A Donate Button!


  1. Leniel Macaferi


    Thanks for this piece of code. It did the job! 🙂

    Leniel Macaferi

    • Sean

      Thanks Leniel. I appreciate the feedback


  2. Jan Andersson

    YES! Just what I needed! 🙂

  3. Mike

    Awesome stuff! I needed a quick way to hide all .svn folders and this did the trick.

  4. Bas

    Thanks man! Great piece of code…

  5. Jason

    Great post. Saved me a ton of time today. Thanks.

  6. Ed

    Thank you for the great .bat file! Saved me a lot of time and effort when I needed it quick!

  7. Jono

    Excellent! Worked well for me…. great help, thanks!

  8. Chris

    Worked a treat, thanks : )

  9. Matt

    Thanks for that – as a Mac user normally, I was aware of the Mac solution, but not of the Windows one. It did work perfectly though.

    However, surely to get a copy of the website for deployment, it would be easier to simply use “svn export” to create a copy of the repository without the .svn folders… just an observation ;o)

    • Sean

      HI Matt, yes you are indeed correct. The Mac version was the real point of the post but it felt right to add a Windows alternative as for some reason some people still use the antiquated Operating System still 🙂 SVN Export would be the way to go I think although sadly no real decent GUI application exists for the Mac. I am more into GIT these days which doesn’t use the same hidden directory structure thankfully.


  10. brondra

    Perfect! thank you

  11. Ventsi

    SVN export is what you need. Open the SVN client your using (your IDE for instance). In the NetBeans for instance you can find export in the menu Team -> Export… (when you’re already connected to the repository). If for some reason you do not have access to the repository, you may use tools like to remove the hidden .svn folders.

    • Sean

      Thanks Ventsi, I wrote this post a couple of years ago but it’s good to know there are now tools to do it which might be easier to work with than the command line.


  12. Jeff

    Changing *svn to *hg will allow this script to remove Mercurial folders (which is what I needed to do). Thanks for writing this script, it saved me alot of time and effort.

  13. Juan

    Man, many many thanks for this script, it saved me a lot of time. Thank you!


Leave a Reply

Divi United

About this site and Sean Barton

Picture of Sean
Sean Barton is a Freelance PHP Website Developer in Crewe, Cheshire. He is a Wordpress and CMS/Framework specialist.
This site was set up in 2008 as a tutorial and scripting resource for the PHP language and Wordpress.
Find out more about Sean on the About Me page or use the Hire Me page to get in touch. For more information about Sean's work take a look at the Portfolio

Our Services

  • Wordpress plugin/theme development
  • Divi specialist
  • Ecommerce (Woocommerce, WPSC, Shopify, Magento)
  • PSD to Wordpress theme conversion (Responsive)
  • Website design work (Banners, Logos, Full Site, etc)
  • Website analysis (security, usability, SEO)
  • API Integrations (InfusionSoft, SalesForce, Ontraport, Customer Thermometer, etc..)
  • Wordpress consultancy & expert advice
  • Crisis support
  • Website hosting

The main services offered are Wordpress based although we do a great deal of technical programming for bespoke systems. From troubleshooting, extending frameworks, finding bugs to writing them from scratch.

Find out more by looking through our past projects or get a quote.

Be the first to hear about new products/updates!

This is a mailing list for those people interested in being told when we release a new product (Divi plugin or Theme).

We shall also use this list to let you know about product updates and releases.

You have Successfully Subscribed!