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
rename multiple files antointoronto Shell Programming and Scripting 13 03-20-2008 10:16 AM
How to rename multiple files with a common suffix er_ashu UNIX for Dummies Questions & Answers 1 09-28-2007 10:52 AM
Rename part of multiple files sajjad02 Shell Programming and Scripting 4 02-22-2005 01:30 PM
Rename multiple files luiz_fer10 UNIX for Dummies Questions & Answers 7 06-11-2002 08:06 AM
Rename Multiple Files molonede UNIX for Dummies Questions & Answers 1 11-14-2000 12:40 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 04-22-2006
tayyabq8's Avatar
tayyabq8 tayyabq8 is offline Forum Advisor  
Moderator
  
 

Join Date: Nov 2004
Location: Bahrain
Posts: 578
how to rename multiple files with a single command

Hi

I have following list of files at a path:

01.AR.asset
01.AR.index
01.AR.asset.vf
01.AR.asset.xv

I want to rename all these files as follows:

73.AR.asset.Z
73.AR.index.Z
73.AR.asset.vf.Z
73.AR.asset.xv.Z

Can any body give me a single command to acheive the above results.

Thnx & Regards,
Tayyab
  #2 (permalink)  
Old 04-22-2006
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
Yeah...but it is a rather complex command and requires a powerful shell (I'm using ksh). We need a pattern that will match those 4 files and only those 4 files. I will assume that 01.AR.* will do that.
Code:
$ ls *AR*
01.AR.asset     01.AR.asset.vf  01.AR.asset.xv  01.AR.index
$ for i in 01.AR.* ; do mv $i 73${i#01}.Z ; done
$ ls *AR*
73.AR.asset.Z           73.AR.asset.xv.Z
73.AR.asset.vf.Z        73.AR.index.Z
$
  #3 (permalink)  
Old 04-23-2006
tayyabq8's Avatar
tayyabq8 tayyabq8 is offline Forum Advisor  
Moderator
  
 

Join Date: Nov 2004
Location: Bahrain
Posts: 578
Thanks Perderabo for your reply. It worked perfectly. Can you pls explain me the 73${i#01} part of this command. It'll be a great favor. Thnx & Rgrds, Tayyab
  #4 (permalink)  
Old 04-23-2006
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
${i} is the value of the variable i
${i#01} is the value of the variable i with any leading "01" removed

That leading 73 is just like the trailing .Z which you didn't ask about. We are just tacking some constant text on to both ends of the value of the variable.
  #5 (permalink)  
Old 04-23-2006
tayyabq8's Avatar
tayyabq8 tayyabq8 is offline Forum Advisor  
Moderator
  
 

Join Date: Nov 2004
Location: Bahrain
Posts: 578
I got it, Thanks for your explanation. This command will save a lot of my time.

Regards,
Tayyab
  #6 (permalink)  
Old 03-18-2008
antointoronto antointoronto is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 28
rename multiple files

Hi tyub,

This is Antony. Do you remember me.? you want to use this in Kerridge AR module.

its like this

for i in *
do
mv $i $i.Z
done

Hopefully this helps you..

Regards,
Antony
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 09:16 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