rename 124 files with long name to short name

My friend give me Two DVD , with full of pink panther cartoon.
all of this file are AVI . for example
Pink panther part1 pink with cow.avi
you see each file have long name .
So I want rename all of them to
pink1.avi
pink2.avi
.
.
.
pink124.avi
I want choose short name for them and save them on my HDD.
How I can do this ?
If I want rename them one by one , it take long time.
 
run this script in directory with avi files

Code:
#!/bin/sh
a=0
for i in `ls *.avi`; do
  mv -f $i `printf "[red]pink[/red]%0.3d.avi" $a`
  a=`expr $a + 1`
done
exit

This should do the trick
 
killasmurf86 said:
run this script in directory with avi files

Code:
#!/bin/sh
a=0
for i in `ls *.avi`; do
  mv -f $i `printf "pink%0.3d.avi" $a`
  a=`expr $a + 1`
done
exit

This should do the trick

Can I this script for Linux BOX or I must modify it .
If I have all parts of Tom and Jerry How I can use this script
 
killasmurf86 said:
I think it should work for linux as well, even on bash

So what I must do when I have all episode of tom and jerry and all episode of prison break
 
killasmurf86 said:

I think I must change pink with tom or prison break
but I think it was better , this script rename all files without edit script.
for example I give this original name and script ask me new name and do this for me
 
well, it's mush easier to change pink to prison_break {or prison_break_season_1_ etc} in script, isn't it

look at my first reply, I marked it red
 
killasmurf86 said:
well, it's mush easier to change pink to prison_break {or prison_break_season_1_ etc} in script, isn't it

look at my first reply, I marked it red

Yes it is true
 
killasmurf86 said:
NOTE: script above will fail on files with spaces (and maybe some special characters in file names).
To avoid this you can run this script first
http://forums.freebsd.org/showpost.php?p=4012&postcount=3

Replace `ls` with something like `find . -name "*"`
"ls" seems to have issues with spaces in file names.
This one removes all empty spaces from files names:

Code:
#!/bin/sh
find . -name "* *" | while read file
do rename "$file" "`echo "$file" | nawk ' BEGIN {OFS=""} $1=$1 '`"
done
 
Back
Top