On 2008-08-29, Bob Proulx wrote: > Tony Zanella wrote: >> I have a directory listing of files like: >> img.bc03.547.1.gif? >> I need to trim the last character off for each file in the dir. >> I know I can use: >> mv img.bc03.547.1.gif? img.bc03.547.1.gif >> to rename each by hand, but I want to do this as a batch. >> I know it would start with: >> for files in *; do; >> after that, I'm stuck! >> Any suggestions? > > The easiest way is to use the 'rename' command which is usually > installed as part of Perl. > > rename --verbose 's/.gif\?$/.gif/' *.gif?
There are at least two different versions of rename, and their syntax differs. > But bash can of course be used to write a small command line program > to do this too. Here is one way (there are many): > > for i in *.gif?; do mv --verbose $i ${i%\?}; done That will break if there are pathological filenames. for i in *.gif?; do mv -v -- "$i" "${i%\?}" done -- Chris F.A. Johnson, webmaster <http://Woodbine-Gerrard.com> =================================================================== Author: Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)