Results 1 to 5 of 5
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 ...
- 10-08-2007 #1Just 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.
- 10-08-2007 #2Linux Engineer
- Join Date
- Nov 2004
- Location
- Ft. Polk, LA
- Posts
- 796
- 10-09-2007 #3
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:
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.Code:for k in $(ls directory/index.fld); do mv $k $k.bad; done;
- 12-03-2007 #4Just Joined!
- Join Date
- Dec 2007
- Posts
- 1
- 06-26-2010 #5Just Joined!
- Join Date
- Jun 2010
- Posts
- 4
for complex renaming schemes or large trees, you may like Fixnames. it is a GPL bash script that does recursive renaming of directories and files ; it includes a progress inidcator, full logging, simple detection of duplicate files, alternate filename, and a --pretend option.
it also includes a sed line to make all names in a tree be valid for windows (the script was developped for a osx->win migration that involved renaming over 12k files)
you can get the script here: david . lutolf . net / dt /ulb / #fixnames



