LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-24-2005, 06:09 AM   #1
NightStranger
LQ Newbie
 
Registered: Dec 2004
Location: North of Germany
Distribution: Ubuntu
Posts: 23

Rep: Reputation: 0
Question 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
 
Old 03-24-2005, 06:48 AM   #2
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Debian, Mint, Puppy, Raspbian
Posts: 3,420

Rep: Reputation: 198Reputation: 198
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
 
Old 03-24-2005, 01:25 PM   #3
NightStranger
LQ Newbie
 
Registered: Dec 2004
Location: North of Germany
Distribution: Ubuntu
Posts: 23

Original Poster
Rep: Reputation: 0
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 .
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....
 
Old 03-25-2005, 11:26 AM   #4
Blinker_Fluid
Member
 
Registered: Jul 2003
Location: Clinging to my guns and religion.
Posts: 683

Rep: Reputation: 63
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"
 
Old 03-26-2005, 06:43 AM   #5
NightStranger
LQ Newbie
 
Registered: Dec 2004
Location: North of Germany
Distribution: Ubuntu
Posts: 23

Original Poster
Rep: Reputation: 0
Thumbs up

Thanks, that works fine and saves me a lot of work
 
Old 10-03-2006, 12:38 PM   #6
xscd
LQ Newbie
 
Registered: Dec 2003
Location: New Mexico, US
Distribution: FreeBSD
Posts: 2

Rep: Reputation: 0
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
 
Old 10-04-2006, 03:25 AM   #7
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,260

Rep: Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328
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.
 
Old 10-04-2006, 03:43 AM   #8
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Code:
rename IMG_0 L_ *jpg


Cheers,
Tink
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
rename files allelopath Linux - General 5 07-05-2005 04:00 AM
rename all files in a directory merlin23 Linux - Newbie 4 03-24-2005 12:02 PM
Files Rename on boot kofrad Slackware 2 05-07-2004 05:50 AM
Can not rename files. Maximus2000 Linux - General 0 04-22-2004 02:36 PM
can't rename files in samba Sathe Linux - Networking 3 02-03-2002 06:20 PM


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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration