Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File & Dir Rename Progress but one problem ...

Status
Not open for further replies.

Autosys

Programmer
Jun 1, 2004
90
GB
Hi All

I have a little script (see below) which should rename all files and directories which match the pattern "bb". The problem however is that the script fails to rename some of the later directories as the script has already renamed some of the earlier directories which these directories live in making the paths invalid, therefore not being able to rename the directory. Is there a way to make the script rename all the files and directories on one level, and then to go into the next level etc etc. {In order to keep the paths valid}? Hope this makes sence?

Thanks!

Something like doing a find . print rename?

#!/bin/ksh

for f in $(find . -name "*bb*" -print); do

mv $f $(echo $f | sed 's!bb!aaa!'); done
 
use -t file then run it again -t dir

E.g.

for f in $(find . -name "*bb*" -type f -print);do

check out the man page for find as it maybe -type file

Mike

"A foolproof method for sculpting an elephant: first, get a huge block of marble, then you chip away everything that doesn't look like an elephant."

 
Thanks for the advice .... I've done the following which seems to work

Having a loop inside of a loop and supressing errors (directories that don't exist anymore to /dev/null).

Probably a bit dodgy so I'll have a look at the above thanks a lot!
S
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top