Archive for the ‘Linux’ category

How to recursively remove .svn directories

July 23rd, 2009

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:
Remove SVN Files (Windows) (82 bytes)

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 – http://snipplr.com/view/201/remove-all-svn-directories/
Windows Version – http://bluespark.tumblr.com/post/23853870/remove-svn-subfolders-on-windows-xp-vista

Linux Server Root Password Retrieval

June 11th, 2009

Here’s an recipe for you… Take one Linux server, add a sprinkle of forgetfullness and leave for an amount of time.

Not a standard recipe I know but this is exactly what I just had to deal with (in my defence it wasn’t me that forgot the password). At work we have a server we rarely use running Redhat (or something close) and with a few staff rotations over recent months the root password literally got lost. Due to an upcoming review of hardware, this password was becoming more and more necessary despite us having limited SSH access to the machine.

After asking a friend and some mutual Googling we came across a guide or two which recommended ways to do the task. I was so pleased with the effectiveness of the information presented that I wanted to provide a link to the site I used and summarise the information on my own site.

For those that don’t like reinventing the wheel visit this link. For the rest of you, read on…

I shall briefly go over the method I used which required physical access to the server and Grub boot loader utilisation. The steps are as follows:

  • Reboot the machine/server and keep an eye out for the GRUB screen.
  • When it does appear then quickly press one of the arrow keys as this page often has a 2-5 second time out before assuming you want the default option.
  • Over the default option press ‘e’ to enter edit mode
  • On the following screen select the line referring to the Kernel and press ‘e’ again
  • At the end of the line add the word ’single’ (with a space before it)
  • Press Escape to exit edit mode and then ‘b’ to boot into single user mode.

Once you have single user access you will automatically have Root access to the machine. Simply type ‘passwd’ at the console and type your new password. You can then type ‘reboot’ and allow the machine to boot as normal then login using your new password.

I did this AFTER trying and failing to use the ‘hard’ method detailed on the Linux forum. So a lesson for the future will be to never assume the worst when it comes to Linux, it’s not always that hard :)

I also took the opportunity to add myself to the sudoers file when I was logged into single user mode. This was simply in case I broke the root password and needed to ’sudo su’ after the reboot. Although not essential it will save you another restart if you mistype the password or break something.