The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Need help renaming files bbbngowc UNIX for Dummies Questions & Answers 5 04-23-2008 11:08 AM
Renaming Files abch624 Shell Programming and Scripting 2 03-19-2008 08:54 PM
renaming files jxh461 UNIX for Dummies Questions & Answers 1 02-04-2008 05:32 PM
Renaming files Tygoon UNIX for Dummies Questions & Answers 7 01-06-2008 06:59 PM
renaming files systemsb UNIX for Dummies Questions & Answers 3 05-24-2006 09:56 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-21-2004
Registered User
 

Join Date: Jan 2004
Location: chennai, india
Posts: 47
Stumble this Post!
renaming files

i have a set of *.lst files. now i want to change the names from "lst" to "dat". how to do it?
ex.:
-rw-r--r-- 1 rram group 22 Sep 21 13:10 a.lst
-rw-r--r-- 1 rram group 22 Sep 21 13:09 b.lst
-rw-r--r-- 1 rram group 22 Sep 21 13:10 c.lst
-rw-r--r-- 1 rram group 22 Sep 21 13:10 d.lst

i want to change all the files suffix to "dat" from "lst"

Replies appreciated.

raguram R
__________________
raguram r
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 09-21-2004
zazzybob's Avatar
Registered Geek
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
Stumble this Post!
If you're using bash, something like

Code:
for file in /path/to/files/*
do
   mv $file `expr substr $file 1 $(( ${#file} - 4 ))`.dat
done
should do the trick...

Cheers
ZB
Reply With Quote
  #3 (permalink)  
Old 09-21-2004
Registered User
 

Join Date: Sep 2004
Posts: 78
Stumble this Post!
perhaps along the pipes..

go into the directory and try something like..

....

find . -name "*.lst" -exec mv "*.dat"

...fortunately it won't work...but when if would be nice
Reply With Quote
  #4 (permalink)  
Old 09-21-2004
zazzybob's Avatar
Registered Geek
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
Stumble this Post!
Quote:
find . -name "*.lst" -exec mv "*.dat"
This will not work. For one thing, you haven't used the actual "found" string (i.e. {} ) and also, you've only supplied one argument to the mv command.

The solution I posted for "bash" (or ksh) is tested and works.

Cheers
ZB
Reply With Quote
  #5 (permalink)  
Old 09-21-2004
Registered User
 

Join Date: Nov 2001
Location: Lille, France
Posts: 20
Stumble this Post!
Hi,

I think you can test this :

for i in `ls -al /YOUR_PATH | awk '{print $9}' |grep .lst`
do
u=`ls $i| sed 's/.lst/.dat/g'`
mv $i $u
done


if you want to change all the .lst file it will be right.

Alex'
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 03:24 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0