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
rename files help piltrafa UNIX for Dummies Questions & Answers 2 10-04-2007 09:47 AM
Need help on installing an EASY to use and easy to install command line text editor EugeneG UNIX for Dummies Questions & Answers 4 07-16-2007 11:53 AM
VI questions : mass changes, mass delete and external insert Browser_ice AIX 1 12-13-2006 04:20 AM
Mass Change content in all files terala Shell Programming and Scripting 1 11-20-2005 01:30 AM
Mass Copy/rename lwilsonFG UNIX for Dummies Questions & Answers 6 11-03-2005 06:55 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-17-2002
Thermopylae Thermopylae is offline
Registered User
  
 

Join Date: Apr 2002
Posts: 2
Easy way to mass rename files?

Hi.
What is the easiest way to rename a bunch of files? For example taking all files ending in ".php3" and rename them to end in ".php"

I could write a script to do this, but there is probably an easier way...

Thanks!
  #2 (permalink)  
Old 04-17-2002
Lexx
Guest
  
 

Posts: n/a
Bits: 0 [Banking]
Are you sure that you want to rename all *.php3 files to *.php files? Take into consideration that you need to alter the files themselves as well then, include()s and require()s for example.

Because I am lazy, I usually make Apache pass the *.php3 files to PHP4 as well, which always worked fine for me.

HTH,
Lexx
  #3 (permalink)  
Old 04-17-2002
Thermopylae Thermopylae is offline
Registered User
  
 

Join Date: Apr 2002
Posts: 2
Yes, I am aware of that. But due to to way my site is designed that is not a big issue, in fact in the few cases where links would break I can do a grep and fix that.

But the rename php was merely an example, I am interested in ways to mass rename files...

Thanks.
  #4 (permalink)  
Old 04-17-2002
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
You need to write an script. Regards. Hugo.
  #5 (permalink)  
Old 04-17-2002
Neo's Avatar
Neo Neo is online now Forum Staff  
Administrator
  
 

Join Date: Sep 2000
Location: Asia Pacific
Posts: 6,680
If you assume the files are in the same directory, for example, the steps would be:
[list=1][*]Open the directory.[*]Read in the name of each file.[*]Copy the file to the new filename.[*]Repeat for all files of interest.[/list=1]

If the files are not in the same directory you could:
[list=1][*]Find the file(s) using the "find" command.[*]Copy the file to a new filename.[*]Repeat.[/list=1]

Do NOT move or delete files in the script or command line filter because if you do AND you make a mistake, you will have lost the files. Copy to new files names first..... after you are sure you are happy with the results, you may consider deleting the old files.

Error on side of caution. BTW, there are other 'cautious ways' to do this... including copying all the files and directory to a temporary directory and operating on the copies first
  #6 (permalink)  
Old 04-17-2002
peter.herlihy peter.herlihy is offline
Registered User
  
 

Join Date: Nov 2001
Location: New Zealand
Posts: 333
Releated to this so I'll add it here.....I've found it difficult to rename files to a truncation of the original filename....and you may find this too Thermopylae

i.e. if I have a bunch of files called random.temp.old and I want to rename then to random.temp (removing the .old)...then I get stuck.

If I use a simple for script.....

For the_file in *.temp.old
do
mv $the_file <<<<what can I use here>>>>
done

I want to use a shorter name - but don't want to have to get into the whole length of the filename and removing 'x' characters from the end of it...... is there a better way?
  #7 (permalink)  
Old 04-17-2002
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
I can't think it without making that, either with "cut -c" command or with the awk command. I prefer awk with substr() and length() functions for the creation of the new_file_name.

It is becoming late for here. Greetings. Hugo.
Closed Thread

Bookmarks

Tags
awk, awk trim, linux, trim, trim awk

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:48 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