#!/bin/sh # This script recursively changes all file/directory names using the filter $* # (filter includes program and arguments to do filtering.) # Iain Murray (c) July 2003. http://www.iainmurray.net # Now this is embarassingly complicated. Is shell really this fiddly, or have I # made this far too hard for myself? # This stops script on any errors: set -e # not doing so would be very dangerous IFS=" " # needed so that read doesn't through away spaces # loop through all file+directory names, but ignore '.' find . -maxdepth 1 | while read a do if [ "$a" != . ] # translate and rename files+directories then b=`echo "$a" | $*` if [ "$a" != "$b" ] then mv "$a" "$b" fi # recurse into directories, but not if it is a link, because # could get into infinite cycles if [ -d "$b" -a ! -h "$b" ] then cd "$b" $0 $* cd .. fi fi done