Command Line

Fix .SVN file permissions with BASH

Thursday, August 12th, 2010

Occasionally I need to checkout a SVN repository as root to get the the correct file structure. I don’t like any of my application files living in /public_html, always one level up. For most enviroments the user account one level up is the user’s /home directory.

A user named bob will log in to /home/bob and the publicly facing directory will be /home/bob/public_html, and the application would live in /home/bob/app with /home/bob/public_html/index.php pointing to the app.

Using the standard SVN file structure the repository would look like http://example-repository.com/bob/trunk/ with the rest of the files inside /trunk.

If you try to checkout from user bob you’ll end up with /home/bob/trunk/app. There are lots of ways around this but I prefer to just checkout as root. We can use chown to fix the file permissions. In some cases you’ll want the group to be nobody. We don’t however want the group nobody to own any svn files.

One liner to fix that.

find -name '.svn' | xargs chown -R bob:bob

This will recursively search for any .svn files and run chown.

Remove your IP from a blocked firewall

Thursday, January 21st, 2010

I only have to do this a couple times a year. This is so I don’t have to look it up.

Open up the file.

pico /etc/apf/deny_hosts

Find your IP and delete the entry. Then restart APF

/etc/init.d/apf restart

There, I wrote it down this time.

Batch image conversions with the command line.

Monday, October 5th, 2009

For the occasions you have a couple dozen or more images to resize.

I’m sure there is a more elegant approach to this. If I had the occasion to do it more often it would be worth a bash script.

The Problem

I have 20 images that are the right size but the file size needs to be reduced from about 150k to 40k. They need to be renamed from DSC-999999.JPG to 0.jpg, 1.jpg etc.

The Solution

First you need to install ImageMagick

$ sudo apt-get install ImageMagick

I create some working directories on the desktop.

From /Desktop

$ mkdir new
$ mkdir new/resized

Put the images to be converted in /new

Now we’ll change the name so they are all .jpg instead of .JPG

From /new

$ rename 'y/A-Z/a-z/' *

Now we’ll make a copy at a lower quality in /new

$ convert *.jpg -quality 60 resized/new.jpg

You can play with -quality to get the size you want.

Now we’ll rename them to the new filenames.

$ rename 's/new-//' *

That’s it. You now have reasonable file sizes to work with on a website. There isn’t anything you can’t do ImageMagick.