Usefull Code for Mass Renaming

Found this snippit of code and thought someone else would find it usefull

This was used to rename a bunch of log files with inconsistant naming schema to all lower case and with a .log extention instead of _log.

#!/bin/bash
### Rename all uppercase directories to lower case ##
# NB : Addapted from from http://www.linuxweblog.com/node/306
 
for x in `find * -type f -maxdepth 0`;
do
  # Translate Caps to Small letters
  y=$(echo $x | tr '[A-Z]' '[a-z]');
  if [ "$x" != "$y" ]; then
    mv $x $y;
  fi
done
 
for x in `find * -type f -maxdepth 0`;
do
  # Rename log files using .log instead of _log to conform to new naming schema
  y=`echo $x | sed "s/_log/.log/"`
  if [ "$x" != "$y" ]; then
    mv $x $y;
  fi
done

Enjoy

The ANAT Tech Department

This entry was posted in Articles. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *