From: Eric Smith
Sent: Friday, December 16, 2011 1:17 AM
Personally I use a shell for loop with mv and
basename, like:
for f in *.foo; do mv $f `basename $f .foo`.bar;
done
That won't work when you want to change something
other than the suffix
of a file, so knowledge of other Unix tools is helpful. For more
complex mass renamings, which I do even less frequently, I do tend to
use sed for filename manipulation. It's more powerful, but not as easy
to use. On the other hand, it's less powerful than Perl. I don't view
that as a disadvantage. I don't want a ten pound sledge when I need to
drive a finishing nail.
For this kind of thing, I revert to tcsh (explicitly invoked from the bash
prompt):
% foreach F (*.foo)
set R=$F:r
mv $F $R.bar
end
All kinds of editing can be accomplished with :h, :t, :r, and :e, so it's
easy to change things other than the suffix. (I have been using ksh and
bash for 20 years, and still can't remember the equivalents of tcsh's
editing modifiers. My guilty secret.)
Rich Alderson
Vintage Computing Sr. Server Engineer
Vulcan, Inc.
505 5th Avenue S, Suite 900
Seattle, WA 98104
mailto:RichA at
vulcan.com
mailto:RichA at
LivingComputerMuseum.org
http://www.LivingComputerMuseum.org/