LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   mass renaming in order (http://www.linuxquestions.org/questions/linux-newbie-8/mass-renaming-in-order-733655/)

KBriggs 06-17-2009 11:52 AM

mass renaming in order
 
Hey all,

I have a folder with 3000 image files that need to be made into a movie. I want to get rid of 90% off them, since they are not needed. Right now I have:

mov0001.png
mov0002.png
mov0003.png
etc.

I can remove 90% of them with the command

rm ./mov???[123456789].png

which will keep only files ending in 0. However, the movie program needs files names in order to work. How can I rename all the remaining files back to

mov0001.png
mov0002.png
mov0003.png
etc

in order?

Is there a (relatively) simple command I can use?

Thanks :)

Uncle_Theodore 06-17-2009 11:55 AM

Well, there's the
rename
command, with somewhat unusual syntax, but it can be useful in your case.

KBriggs 06-17-2009 11:57 AM

Could you give me some more details? I am new to linux. I have seen a few references to the rename command, but am as yet unsure what format strong I would need to recognize the files I am looking for.

I would need to rename

mov0010
mov0020
mov0030
mov0040
etc

to

mov0001
mov0002
mov0003
mov0004

etc

colucix 06-17-2009 11:59 AM

If you list them, they should be already sorted by name, so that you can do a simple loop:
Code:

count=0
for file in *.png
do
  ((count++))
  echo mv $file mov$(printf "%04d" $count).png
done

The echo command is just for safety. Test it as is and the mv command will be simply echoed without actually being executed. Check the result, then remove the echo command and run again.

KBriggs 06-17-2009 12:02 PM

Cool thanks :)

time to learn shell scripting I think

Tinkster 06-17-2009 12:02 PM

Hi,

Welcome to LQ.

Code:

#!/bin/bash
count=1
for i in *
do
  name=$( printf "mov%.4d.png" $count )
  mv "$i" "$name"
  count=$(( $count + 1 ))
done

Should work.


Cheers,
Tink


P.S.: Heh ... toooooo slow.


All times are GMT -5. The time now is 01:51 PM.