APLawrence.com -  Resources for Unix and Linux Systems, Bloggers and the self-employed

rename files script

In article <noemail-308131.02144511022003@cnews.newsguy.com>, Hobo
<noemail@noemail.com> wrote:

> hello,
> I have 77 images named 0.gif through 76.gif, but I need them to be named 
> 1.gif through 77.gif.
> Is there a freeware app which will do this for me?

I doubt it, but it's not hard to do at the shell.  The only real tricky
part is that you need to work backwards, starting at 76.gif and moving

Save this as "renameit" and  then chmod 755 renameit

for i in $(ls *.gif| sort -nr)
  x=$((${i%.gif} + 1))
  echo mv $i $x.gif

Watch the paren's and the brackets: that's x=dollar paren paren dollar
bracket i percent .gif closebracket space plus 1 closeparen closeparen

Once you are happy that will do what you want, take the "echo" out of
the next to last line and run it again.

> I also believe that one of the images may be wrong, but it will be 
> easier to tell after I have renamed them. Once I find the wrong one I 
> will have to erase it and then rename all others after it. That's why 
> I'm to lazy to do it by hand.

And you'll just need a slight modification of the script to handle that.

Tony Lawrence
Learn more about SCO Unix, Mac OS X  or  Linux 
Free Sample Download:  http://aplawrence.com/skillstest.html

Got something to add? Send me email.

Increase ad revenue 50-250% with Ezoic

More Articles by

Find me on Google+

© Tony Lawrence

Kerio Samepage

Have you tried Searching this site?

Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more.

Contact us

While modern technology has given people powerful new communication tools, it apparently can do nothing to alter the fact that many people have nothing useful to say. (Leo Gomes)

This post tagged: