Batch renaming of files is often needed when files need to be transformed from one naming convention into another. This can require replacement patterns of varying complexity. Prior solutions to this problem exist, but are all limited in various ways—for example, they might not provide regular expression patterns, or only allow for a single regular expression to be used.
Important features to be considered in a batch renaming script are a test mode in which the actions to be taken are printed, but not executed, an interactive mode which requests confirmation for every change, as well as the support for multiple expressions per rename batch.
For a long time, I used the following idiom:
for i in *
do
mv "$i" "$(echo "$i"
| sed -e 'regex1'
-e 'regex2'
...)"
done
By adding an echo in front of the mv,
this provides testing. Interactivity can be added, but it gets even
more ugly. And of course, rewriting this idiom all the time is rather
annoying.
The rename program downloadable below provides all of
the requested features. It is written
in the Scheme Shell scsh.