Piping grep to rm

I discovered a neat trick to deleting folders/files based on a pattern. Let’s say you have a directory structure like this:

/test
/test/aaaa
/test/bbbb
/test/cccc
/test/ddd
/test/eee
/test/fff

You’ve decided that any folder with a’s, b’s, or c’s has to go. You definitely don’t want to delete them all by hand; especially if there are a couple thousand of them. The first thing you need to do is find the directories that you want to remove:

  1. ls | grep "[a-c]"

Which produces the following:
aaaa
bbbb
cccc

Great! Now what? All you need to do is pipe that to rm using xargs:

  1. ls | grep "[a-c]" | xargs rm -rf

All files that match the given pattern will be deleted. But, be careful that the pattern only matches the files you would like to delete. Run ls | grep first before you pipe anything to rm, unless you like trying to restore deleted files.

Technorati :

Dead simple dependencies with grails + ivy

It is unbelievably easy to integrate Ivy as a dependency manager for your grails application. Just a couple of steps really (Note: this is for grails >= 1.0 as < 1.0 had ivy integrated):

  1. Install the Ivy plugin:
    1. grails install-plugin ivy

    This will create an ivy.xml and an ivyconf.xml, and place them in the project root. I modified my ivy.xml thusly:

    1. <ivy-module version="1.0">
    2.    <info organisation="codehaus" module="grails"/>
    3.    <dependencies>
    4.        <dependency org="mysql" name="mysql-connector-java" rev="5.0.5"/>
    5.    </dependencies>
    6. </ivy-module>
  2. You can then run the following command and ivy will place your dependencies in the lib folder of your project root:
    1. grails get-dependencies

That’s it! Now I just need to figure out why they don’t really use this as a selling point for grails. The only thing I can figure is that there are so many great features it would get lost in the list anyway.