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
how to change permissions only to files, not directories....? narrok UNIX for Dummies Questions & Answers 3 12-13-2008 03:55 AM
Batch changing file extensions cdines Shell Programming and Scripting 5 05-19-2008 06:11 AM
A Batch job to delete files from various directories guruparan18 Shell Programming and Scripting 3 05-10-2008 05:31 PM
simple batch renaming...45-*.php to 46-*.php bcamp1973 UNIX for Dummies Questions & Answers 2 11-01-2006 10:51 AM
Change permission for directories and files mingfei2006 Shell Programming and Scripting 1 08-23-2006 08:00 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 07-20-2008
dave920 dave920 is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 6
Question Batch Renaming: Change files' extensions in many sub-directories

Hi all -

I'm trying to rename a large number of files all at once and need some help figuring out the command line syntax to do it. I've already done quite a bit of research with the rename and mv commands, but so far haven't found a solution that seems to work for me. So:

The files exist here:

/public_html/files

However, there are many subdirectories within /public_html/files, and the files within those subdirectories must also be renamed with the same operation. (I'm hoping to be able to rename the files in those subdirectories at the same time, since going through every single one of the sub-dirs -- there are 1000s -- would be very time consuming.)

The files that need renaming are, shall we say, .zzz files. All of them end in .zzz, but the beginnings of their file names are, of course, different.

NOTE: There are OTHER files in these directors that are NOT .zzz files (let's say .jpg files), and those files CANNOT be affected by this rename command.

Let's say I would like to rename all .zzz files within all subdirectories to .zzz_disabled (basically, to disable these files from being accessed), but keep the first part of their file names in tact.

So:

dog_ran_up_the_hill.zzz

BECOMES

dog_ran_up_the_hill.zzz_disabled

And that's pretty much it!

I think I've included all necessary info here.

Can anyone help me come up with the proper command line syntax to batch rename all the files in all the directories?

Thanks so much!
  #2 (permalink)  
Old 07-20-2008
rubin's Avatar
rubin rubin is offline Forum Advisor  
Registered User
  
 

Join Date: Nov 2007
Posts: 321

Code:
find /public_html/files  -type f -name "*.zzz" | xargs -i mv '{}' '{}'_disabled

First run the find command without the xargs part to make sure you have only the files that you need, then proceed with xargs addition.

Last edited by rubin; 07-20-2008 at 01:18 AM.. Reason: then proceed with xargs addition.
  #3 (permalink)  
Old 07-20-2008
dave920 dave920 is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 6
I tried the find command, and it didn't turn up anything
  #4 (permalink)  
Old 07-20-2008
rubin's Avatar
rubin rubin is offline Forum Advisor  
Registered User
  
 

Join Date: Nov 2007
Posts: 321
Quote:
Originally Posted by dave920 View Post
I tried the find command, and it didn't turn up anything
The command works fine. You need to be more specific.
  #5 (permalink)  
Old 07-20-2008
dave920 dave920 is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 6
This is the message I get when I enter the command:


Code:
find: /public_html/files: No such file or directory

  #6 (permalink)  
Old 07-20-2008
rubin's Avatar
rubin rubin is offline Forum Advisor  
Registered User
  
 

Join Date: Nov 2007
Posts: 321
Quote:
Originally Posted by dave920 View Post
This is the message I get when I enter the command:


Code:
find: /public_html/files: No such file or directory

What is your OS ?
Closed Thread

Bookmarks

Tags
batch, command, linux, linux commands, rename, solaris

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 08:25 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