Rename files in directory with some regex magiks

April 12, 2011

When using drupal I often want to clone a module as a starting point for a new module. I then have to rename all the files in the directory to the new structure. This can be painful if there is more than one file. All files in drupal follow the file naming convention of :
So the following bash script will niftily go through a directory renaming all the files with module1 and replace with module2…

for f in *; do mv $f `echo $f | sed 's/module1\(.*\)/module2\1/g'`; done



  1. Hi

    I used to do something similar until I discovered the rename command.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: