unix rename

Tags
beginners

 

 
Thread Tools Search this Thread
# 1  
Old 07-11-2004
unix rename

Whats the command in unix to do this ;


rename a bunch (3000) of files called ;

0001.jpg
0002.jpg
0003.jpg
0004.jpg

to

0001_LRG.jpg
0002_LRG.jpg
0003_LRG.jpg
etc.


i.e. adding the extension _LRG to the end of the filename ?

Ive tried rename ????.jpg ????_LRG.jpg but no luck ?

Anyone ?
# 2  
Old 07-12-2004
Try this....

for i in [0-9][0-9][0-9][0-9].jpg
do
mv $i ${i%.jpg}_LRG.jpg
done
# 3  
Old 07-13-2004
Quote:
Originally posted by Ygor
Try this....
for i in [0-9][0-9][0-9][0-9].jpg
do
mv $i ${i%.jpg}_LRG.jpg
done
Is there another way to do it?
# 4  
Old 07-14-2004
Quote:
Originally posted by milhan
Is there another way to do it?
There are lots of ways of doing it, but what's wrong with the method Ygor posted? It's quick and easy.

You could write solutions in Perl, C, XYZ to do this....

e.g. in Perl
Code:
#!/usr/bin/perl

opendir(DIR,".") or die;

while( defined( $file = readdir( DIR ) ) ) {
   next if $file =~ /^\.\.?$/;  # ignore . and ..

   if ( $file =~ /\.jpg/ ) {
      ( $newname = $file ) =~ s/(.*)\.jpg/\1_LRG.jpg/g;
      rename( $file, $newname );
   }
}

closedir(DIR);

but what's the point adding unnecessary complexity?!

Cheers
ZB

Last edited by zazzybob; 07-14-2004 at 11:07 AM..
 

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
Using rename kristinu Shell Programming and Scripting 1 02-20-2018 03:08 PM
Using rename kristinu UNIX for Dummies Questions & Answers 4 03-23-2014 07:19 PM
Rename all Files in a UNIX Directory from one date format to another date format pchegoor UNIX for Dummies Questions & Answers 1 10-25-2013 03:32 AM
Help with Unix file rename Mohammad T Khan UNIX for Dummies Questions & Answers 4 11-25-2011 10:52 PM
How to rename a file even when it shows permission Denied in Unix Haimanti Shell Programming and Scripting 2 12-06-2010 05:28 AM
Multiple file rename (change in filename in unix with single command moon_22 Shell Programming and Scripting 6 11-09-2010 02:08 AM
Unix Command to rename a file in a zipped folder Victoria.Sam UNIX for Advanced & Expert Users 1 04-21-2010 07:09 PM
Rename a file sequencially in UNIX rechever Shell Programming and Scripting 5 03-15-2010 11:35 AM
How UNIX/AIX handles a file deep down, say it's being read while another one tries to rename it? TheGunMan UNIX for Advanced & Expert Users 2 01-08-2010 04:30 PM
need help with rename farhan_t49 UNIX for Dummies Questions & Answers 8 05-24-2009 09:40 PM
copy/rename file as date() unix/shell hdogg Shell Programming and Scripting 1 12-02-2008 09:30 PM
[Unix] a dos style rename wont work fblade1987 Shell Programming and Scripting 3 04-19-2008 03:24 PM
how can I rename the following=-^ nj78 UNIX for Dummies Questions & Answers 5 09-30-2005 02:13 AM
rename using mv ? simon2000 UNIX for Dummies Questions & Answers 2 03-19-2004 04:46 AM
How Do I rename a unix file contianing spacing? frankyranky UNIX for Advanced & Expert Users 7 08-20-2002 07:19 AM