Skip to content

Instantly share code, notes, and snippets.

@sn00011
Created August 23, 2012 08:48
Show Gist options
  • Save sn00011/3434364 to your computer and use it in GitHub Desktop.
Save sn00011/3434364 to your computer and use it in GitHub Desktop.
Batch replace a portion of the file names in a directory

This may use the utility 'rename', in case not installed(OS X), install it using:

$ brew install rename

==> Downloading http://plasmasturm.org/code/rename/rename
######################################################################## 100.0%
==> pod2man rename rename.1
/usr/local/Cellar/rename/0.1.3: 3 files, 28K, built in 6 seconds

For example, i want to rename all the files under this folder from views_exposedfilters_facets.* to message_library_exposedfilter.*

$ tree message_library_exposedfilter

├── css
│   └── views_exposedfilters_facets.css
├── js
│   └── views_exposedfilters_facets.js
├── templates
│   ├── views_exposedfilters_facets_block.tpl.php
│   └── views_exposedfilters_facets_link.tpl.php
├── views_exposedfilters_facets.info
├── views_exposedfilters_facets.install
└── views_exposedfilters_facets.module

3 directories, 7 files

This method doesn't use rename:

for file in `find . -type f `; do mv $file ${file/views_exposedfilters_facets/message_library_exposedfilter}; done

The result will be:


views_exposedfilters_facets/
├── css
│   └── message_library_exposedfilter.css
├── js
│   └── message_library_exposedfilter.js
├── message_library_exposedfilter.info
├── message_library_exposedfilter.install
├── message_library_exposedfilter.module
└── templates
    ├── message_library_exposedfilter_block.tpl.php
    └── message_library_exposedfilter_link.tpl.php

3 directories, 7 files

References:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment