You are here

Rename Drupal Module/Feature via CLI

Have you ever created a Drupal module (or Feature) only to later realize that the name you've given it needs to be changed?

Not to worry, a couple of quick one-liners will solve this problem easily.

First, change the directory name of your old module.

mv old_module new_module

Move into the newly renamed directory.

cd new_module

Install rename if you don't have it already.

brew install rename

Now use the rename utility to change all the filenames within the directory.

rename 's/old_module/new_module/g;' *

Now for the fun part. Pretend you're a perl monk and use one line to rename each instance of 'old_module' to 'new_module' inside the files!

perl -pi -w -e 's/old_module/new_module/g;' *

That's it... optionally, use ack-grep (or just "ack" on Homebrew) to check your work.

ack-grep -a new_module
Submitted by brant on Thu, 01/24/2013 - 17:09