Welcome to Linux Forums!

With a comprehensive Linux Forum, information on various types of Linux software and many Linux Reviews articles, we have all the knowledge you need a click away, or accessible via our knowledgeable members.

Linux Forum ArticlesLinux ForumsLinux Forum DownloadsLinux Hosts
Home|Register|FAQ|Member List|Calendar|Unanswered Posts|Forum Rules|Today's Posts|Advanced Search|
SEARCH FOR IN
Go Back   Linux Forums > GNU Linux Zone > Linux Newbie
Reload this Page Recursive BASH Rename script
Linux Forums
Linux Forums
Welcome To The Linux Forums!
Welcome to Linux Forums. We pride ourselves in being one of the largest Linux communities on the web, we encourage you to REGISTER on our forums and participate in the community. There are over 150,000 members ready to answer your questions. JOINING US today will allow you to make new posts, get support, send messages to other members and submit downloads to our downloads directory and many other great features!

Linux Newbie If you're new to the wonderful world of Linux, start here!

Reply
 
Thread Tools Display Modes
Old 10-08-2007   #1 (permalink)
MrTubz
Just Joined!
 
Join Date: Oct 2007
Posts: 1
Recursive BASH Rename script

Hi

I need to write a bash script that will go through all subdirectories and replace the filename index.fld with index.bad

I have an email server that requires you to do this if I need to rebuild a mailbox. There is an index.fld file every folder that a user creates in their mail account, so it becoming a pain to rename them all.


I have looked around google and have found bits of script that when i put them together dont work.

I think i can search the files using the find commands but I cant seem to actually rename the file properly.

Any ideas would be greatly appreciated.
MrTubz is offline   Reply With Quote
Old 10-08-2007   #2 (permalink)
valan
Linux Engineer
 
Join Date: Nov 2004
Posts: 785
http://tldp.org/LDP/abs/html/
valan is offline   Reply With Quote
Old 10-09-2007   #3 (permalink)
flipjargendy
Linux Enthusiast
 
flipjargendy's Avatar
 
Join Date: Aug 2004
Location: Herschel, Mimas, Saturn
Posts: 557
Just a suggestion.

I know how to change multiple files within one directory but not subdirectories. In the following case the script would be renaming the files named index.fld to index.fld.bad. It might help you.

You can type the following in the command line or put it in an executable text file:

Code:
for k in $(ls directory/index.fld); do mv $k $k.bad; done;
If you could add a for statement that would ad a /* each time the script was completed you could make it start from directory/index.fld and go to directory/*/*/index.fld... as far as you needed.
__________________
Running Linux Since 2001®
Registered Linux User #430868 - Since 9•12•06
New to Linux? Read this!
flipjargendy is offline   Reply With Quote
Old 12-03-2007   #4 (permalink)
jcmunioz
Just Joined!
 
Join Date: Dec 2007
Posts: 1
Quote:
Originally Posted by MrTubz View Post
Hi

I need to write a bash script that will go through all subdirectories and replace the filename index.fld with index.bad
You can use the find command for this:

find dir -name index.fld -exec mv {} `basename {}`/index.bad \;
jcmunioz is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash script to rename files LinuxDummie Linux Programming & Scripting 16 07-04-2007 01:04 AM
How to set up cron job to execute bash script lgmqy2000 Linux Newbie 2 06-09-2007 02:34 AM
Rename bash script help Cyberian Linux Newbie 3 10-27-2005 09:51 AM
Install_all script not working Red Hat 9 Aston Villa Installation 8 08-22-2003 12:37 AM




All times are GMT. The time now is 06:12 AM.




© 2000 - 2008 - All Rights Reserved - Property of  MAS Media

Content Relevant URLs by vBSEO 3.0.0