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

rename files script


© December 2004 Tony Lawrence

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
down.


Save this as "renameit" and  then chmod 755 renameit

#!/bin/bash
for i in $(ls *.gif| sort -nr)
do
  x=$((${i%.gif} + 1))
  echo mv $i $x.gif
done





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:  https://aplawrence.com/skillstest.html
 

Got something to add? Send me email.





(OLDER)    <- More Stuff -> (NEWER)    (NEWEST)   

Printer Friendly Version

->
-> rename files script


Inexpensive and informative Apple related e-books:

Take Control of Upgrading to El Capitan

iOS 10: A Take Control Crash Course

Digital Sharing Crash Course

Take Control of the Mac Command Line with Terminal, Second Edition

Take Control of Automating Your Mac




More Articles by © Tony Lawrence




Printer Friendly Version

Have you tried Searching this site?

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


Printer Friendly Version





The man who receives five thousand dollars a year wants six thousand dollars a year, and the man who owns eight or nine hundred thousand dollars will want a hundred thousand dollars more to make it a million, while the man who has his millions will want everything he can lay his hands on and then raise his voice against the poor devil who wants ten cents more a day. (Samuel Gompers)




Linux posts

Troubleshooting posts


This post tagged:

Scripting

Shell



Unix/Linux Consultants

Skills Tests

Unix/Linux Book Reviews

My Unix/Linux Troubleshooting Book

This site runs on Linode





SCO Unix Sales, Support, & Service

Phone:  707-SCO-UNIX (707-726-8649Toll Free: 833-SCO-UNIX (833-726-8649)
www.SCOsales.com