On Wed, Jan 10, 2007 at 06:46:28PM -0500, J. Milgram wrote:
>> in each directory used by the CMS.  Any idea how I might have done this
>> recursively?
> !#/bin/bash
> for f in `find . -type f -name \*.php`; do mv -v $f ${f}5; done

find . -type f -name \*.php -exec mv -i '{}' '{}'5 \;

This takes advantage of the fact that you're renaming .php -> .php5 - that
is, the exact same filename except with a 5 tacked on.

>> I now have a whole bunch of references to non-existent .php files in
>> this system.  Any way I could do a recursive find/replace in the textual
>> content of a given directory?
> 
> !#/bin/bash
> for f in `find . -type f`; do mv -v $f $f.bak; sed 's/php/php5/g' $f.bak > 
> $f; done

Can't improve on this one beyond:

for f in `find . -type f -exec grep -q php '{}' \; -print`; do

Although I'd be concerned abound find going bonkers and finding all the
.bak files that had just been made.  Perhaps:

#!/bin/bash
find . -type f -exec grep -q php '{}' \; -print > /tmp/PHPLIST.eoin
while read f < /tmp/PHPLIST.eoin; do
  mv -iv $f $f.bak
  sed 's/php/php5/g' $f.bak > $f
done
rm /tmp/PHPLIST.eoin

Note that under Solaris, to get grep -q to work, you need to usr
/usr/xpg4/bin/grep, not the normal grep.  This also assumes that none of
your files have spaces in the name.  If they do, you can try to make the
find command do it all with multiple -exec commands, but I am concerned
about the .bak files making trouble.

Ben
-- 
Ben Stern             UNIX & Networks Monkey             [EMAIL PROTECTED]
This post does not represent FTI, even if I claim it does.  Neener neener.
UM Linux Users' Group     Electromagnetic Networks      Microbrew Software

Reply via email to