The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Renaming multiple files jayell Shell Programming and Scripting 7 01-12-2009 04:27 PM
Moving multiple files and renaming them on the fly daemongk Shell Programming and Scripting 1 06-08-2007 01:36 PM
moving and renaming multiple files rocinante Shell Programming and Scripting 1 06-07-2007 08:20 PM
Renaming multiple files rmayur UNIX for Dummies Questions & Answers 6 02-26-2004 04:40 AM
renaming multiple files piltrafa UNIX for Dummies Questions & Answers 6 11-10-2001 12:27 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-31-2003
jxh461 jxh461 is offline
Registered User
  
 

Join Date: Jun 2002
Posts: 49
Question Renaming multiple files

Can someone please tell me how I can rename a bunch of files at a time. I hava a directory that has 700+ files that are named
*.xyz and I would like to rename them to *.abc . How can I do that with a simple command ?

mv *.xyz *.abc did not work.

Thanks in advance
  #2 (permalink)  
Old 04-01-2003
hugo_perez hugo_perez is offline
Registered User
  
 

Join Date: Apr 2002
Location: Argentine - that better than to eat meat and to drink wine (both Argentineans)?.
Posts: 132
For example ...

There are a lot of ways, for example you can try with:

cd /<your_directory>

for myfile in *.xyz
do
file_name=`echo $myfile |awk '{print substr($1,1,length($1)-4)}'`
echo "mv $file_name.xyz $file_name.abc"
done



Note: when you are sure remove the echo and the quotes.
from: echo "mv $file_name.xyz $file_name.abc"
to: mv $file_name.xyz $file_name.abc


Regards. Hugo
  #3 (permalink)  
Old 04-01-2003
Optimus_P Optimus_P is offline Forum Advisor  
flim flam flamma jamma
  
 

Join Date: May 2001
Location: Chicago IL, USA
Posts: 1,006
Re: For example ...

Quote:
Originally posted by hugo_perez
There are a lot of ways, for example you can try with:

cd /<your_directory>

for myfile in *.xyz
do
file_name=`echo $myfile |awk '{print substr($1,1,length($1)-4)}'`
echo "mv $file_name.xyz $file_name.abc"
done



Note: when you are sure remove the echo and the quotes.
from: echo "mv $file_name.xyz $file_name.abc"
to: mv $file_name.xyz $file_name.abc


Regards. Hugo
why all the substr biz?

why not just: file_name=`echo $myfile|awk -F. '{ print $1 }'`

or even

for i in `ls *.xyz`;do
mv $i $i.abc
done
  #4 (permalink)  
Old 04-01-2003
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
Re: Re: For example ...

Quote:
Originally posted by Optimus_P

for i in `ls *.xyz`;do
mv $i $i.abc
done
That would rename file.xyz to file.xyz.abc which is (probably) not what we want here.

I use ksh (I may have mentioned that before). In ksh, you can use ${i%.*} to strip off the the file suffix.

So if ksh is your interactive shell, this command line will do it:
for i in *.xyz ; do mv $i ${i%.*}.abc ; done
  #5 (permalink)  
Old 04-01-2003
jxh461 jxh461 is offline
Registered User
  
 

Join Date: Jun 2002
Posts: 49
Many thanks to all.
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:58 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0