Yes, it's csh, should be sh. Run in order, it fixes the 200* entries, then the 199* entries. foreach dir ( `find . -type d -depth 1 -name "adsl.archive.0[0-9][0-9][0-9]"` ) mv $dir `echo $dir | sed 's#adsl.archive.\([0-9][0-9]\)\([0-9][0-9]\)#adsl.archive.20\1_\2#'` end foreach dir ( `find . -type d -depth 1 -name "adsl.archive.[0-9][0-9][0-9][0-9]"` ) mv $dir `echo $dir | sed 's#adsl.archive.\([0-9][0-9]\)\([0-9][0-9]\)#adsl.archive.19\1_\2#'` end