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 > 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 02:08 PM
Renaming Files abch624 Shell Programming and Scripting 2 03-20-2008 12:54 AM
renaming files jxh461 UNIX for Dummies Questions & Answers 1 02-04-2008 09:32 PM
Renaming files Tygoon UNIX for Dummies Questions & Answers 7 01-06-2008 10:59 PM
renaming files systemsb UNIX for Dummies Questions & Answers 3 05-25-2006 12:56 AM

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 09-21-2004
raguramtgr raguramtgr is offline
Registered User
  
 

Join Date: Jan 2004
Location: chennai, india
Posts: 47
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
  #2 (permalink)  
Old 09-21-2004
zazzybob's Avatar
zazzybob zazzybob is offline Forum Advisor  
Registered Geek
  
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
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
  #3 (permalink)  
Old 09-21-2004
svennie svennie is offline
Registered User
  
 

Join Date: Sep 2004
Posts: 78
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
  #4 (permalink)  
Old 09-21-2004
zazzybob's Avatar
zazzybob zazzybob is offline Forum Advisor  
Registered Geek
  
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
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
  #5 (permalink)  
Old 09-21-2004
farzolito farzolito is offline
Registered User
  
 

Join Date: Nov 2001
Location: Lille, France
Posts: 20
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'
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 10:50 PM.


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