Previously, I would use complex and cumbersome BASH constructs using "for;do;done", "sed", "awk" etc., coupled with the operation itself:
$ for f in *.txt; do mv $f $(echo $f | sed -e 's/foo\(\d\+\)_\(.*\)\.txt/bar_\1_blah_\2.txt/'); done
Which almost always involved a "pre-flight" dummy run to make sure the reg-ex's were correct:
$ for f in *.txt; do echo mv $f $(echo $f | sed -e 's/foo\(\d\+\)_\(.*\)\.txt/bar_\1_blah_\2.txt/'); done
This approach works well enough, but apart from being a little cumbersome (especially if there is any fiddling to get the reg-ex's right), is a little error-prone.
Now, the whole directory gets loaded up into the editor's buffer (the "editor" being whatever '
$EDITOR' is set to), for you to edit as you wish. When done, saving and exiting results in all the changes being applied to the directory. This allows you to bring the full power of regular expressions, line- and column-based selections etc., to bulk renaming and other operations. Best of all, you get to see the final set of proposed changes in your text editor before committing to the actual operation.
All of this can be rephrased as: 'fantastic!'
To get a dose of this filesystem management awesomeness in your world: