LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   how to rename many similar files? (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-rename-many-similar-files-305416/)

NightStranger 03-24-2005 05:09 AM

how to rename many similar files?
 
Hello,

I have a list of files like:

IMG_0052.jpg
IMG_0053.jpg
IMG_0054.jpg
IMG_0055.jpg
IMG_0056.jpg
IMG_0057.jpg
IMG_0058.jpg
IMG_0059.jpg
(.....)
IMG_0365.jpg

and I need to rename them to

L_000.jpg
L_001.jpg
L_002.jpg
L_003.jpg
(...)

How do I do that in an economical way?

(I have already tried "mv" and "rename" but I did not find out how to change the consecutive numbering)

Thanks for help

Stranger

bigearsbilly 03-24-2005 05:48 AM

Code:




billym.primadtpdev>for file in *.jpg;do echo mv $file L_${file#IMG};done
mv IMG_0053.jpg L__0053.jpg
mv IMG_0054.jpg L__0054.jpg
mv IMG_0055.jpg L__0055.jpg
mv IMG_0056.jpg L__0056.jpg


NightStranger 03-24-2005 12:25 PM

Quote:

>for file in *.jpg;do echo mv $file L_${file#IMG};done
does not work here :(
although it generates lines like

mv IMG_0052.jpg L__0052.jpg
mv IMG_0053.jpg L__0053.jpg
mv IMG_0054.jpg L__0054.jpg
mv IMG_0055.jpg L__0055.jpg
mv IMG_0056.jpg L__0056.jpg
(...)

but when I do ls -l the filenames have remained unchanged :confused:.
I still get

-rwxrwxrwx 1 raimoed users 181075 2005-03-24 10:19 IMG_0052.JPG
-rwxrwxrwx 1 raimoed users 181075 2005-03-24 10:19 IMG_0053.JPG
-rwxrwxrwx 1 raimoed users 165190 2005-03-24 10:19 IMG_0054.JPG
-rwxrwxrwx 1 raimoed users 161017 2005-03-24 10:20 IMG_0055.JPG
-rwxrwxrwx 1 raimoed users 162929 2005-03-24 10:20 IMG_0056.JPG
-rwxrwxrwx 1 raimoed users 162305 2005-03-24 10:21 IMG_0057.JPG
-rwxrwxrwx 1 raimoed users 161976 2005-03-24 10:21 IMG_0058.JPG
(...)

When I execute manually

mv IMG_0053.jpg L__0053.jpg it does work and will change the filename as ecpected.

I also got this with the command
Code:

rename IMG_ L_ IMG*
but I also need to change the numbering starting from 000 instead of 052. This seems to be much more tricky....

Blinker_Fluid 03-25-2005 10:26 AM

Try this...
Code:

count=1;
for file in *.jpg;do echo mv $file L_$count.JPG; count=`expr $count + 1`;done > /tmp/junk_output1
grep L_[0-9].JPG /tmp/junk_output1 | sed 's/[0-9].JPG/00&/' > /tmp/script2run
grep L_[1-9][0-9].JPG /tmp/junk_output1 | sed 's/[0-9][0-9].JPG/0&/' >> /tmp/script2run
grep L_[1-9][0-9][0-9].JPG /tmp/junk_output1 >> /tmp/script2run
chmod 755 /tmp/script2run
cat /tmp/script2run
echo "review the commands above and execute /tmp/script2run to move the files"


NightStranger 03-26-2005 05:43 AM

Thanks, that works fine and saves me a lot of work:)

xscd 10-03-2006 11:38 AM

mvb shell script (bash or sh) file renaming utility
 
Hello--

If you like, you could try my shell script mvb, which I wrote expressly to make it easy to rename a lot of files at once. mvb has a homepage a icewalkers.com (I can't post the URL because I have not yet posted 3 messages to linuxquestions.org, so search for "mvb" at icewalkers) :)

best wishes,

Steve Doonan
New Mexico US

chrism01 10-04-2006 02:25 AM

Actually, Billy used the echo cmd so you can see what the generated cmd would/should be, but without it actually doing anything.
This is a safety measure so you can be sure what will happen before you use it for real.
Remove the 'echo' cmd and you'll be good to go.

Tinkster 10-04-2006 02:43 AM

Code:

rename IMG_0 L_ *jpg


Cheers,
Tink


All times are GMT -5. The time now is 08:03 PM.