mass rename _svn directories to .svn (and vice versa)

November 8th, 2007
This is rather useful if you're dealing with both .svn and _svn subversion directories in your projects. (I think only those who use the ASP.NET hack are suffering from this...) Here is described how to recursively rename all of your .svn directories to _svn (or the opposite).

This is the command that you have to run on GNU/Linux:

find project-name -type d -name .svn | gawk '{print "mv \""$0"\" \""substr($0,1,length($0)-4)"_svn\""}' | sh

Of course you will have to replace project-dir with the path where your project lies. If you want to do the opposite (that is, rename all _svn directories to .svn) you just have to switch their positions in the command.

But as I said before mostly Windows users are going to need this, so this is how you do the same thing on Windows XP:

find project-name -type d -name .svn | gawk "{print \"mv \\\"\"$0\"\\\" \\\"\"substr($0,1,length($0)-4)\"_svn\\\"\"}" > rename.bat && rename.bat && del rename.bat

This is a little more obscure but it works. Two things you have to notice are:

1) We make use of two GNU commands, find, gawk and mv, which are not available on Windows XP by default. You will have to install GNU utilities for Win32 which is something you should do anyway if you are seriously using your Windows XP command line.

2) We are using a temporary .bat file that all the mv commands are stored, and then we execute this .bat file in order for the mv commands to actually take place. This is done because there is no shell by default that can receive and execute commands from the standard input.

One Response to “mass rename _svn directories to .svn (and vice versa)”

  1. Chris Cohen Says:
    Thanks very much. This was incredibly helpful and did exactly what I was looking for. Without this, it might have been a painful process renaming thousands of folders!

Leave a Reply