Hello All,
Assuming i have a thousand symlinks under directory /mydir (and its sub-dir) such as:
mysymlink1 -> ../../../myfoo/mysymlink1
mysymlink2 -> ../../../myfoo/mysymlink2
How can I search the string "myfoo" and replaced with "yourfoo" such that after the operation is complete the /mydir will look like this:
mysymlink1 -> ../../../yourfoo/mysymlink1
mysymlink2 -> ../../../yourfoo/mysymlink2
======
Thanks!
This is a little on the dangerous side to say the least. Run this script...it will produce a second script. Examine that second script carefully before you run it.
#! /usr/bin/ksh
function dodir
{
typeset fname data savedir
ls | while read fname ; do
if [[ -L $fname ]] ; then
data=$(ls -l $fname)
data=${data##* }
data=$(echo "$data" | sed 's=myfoo=yourfoo=')
echo rm $1/$fname
echo ln -s $data $1/$fname
elif [[ -d $fname ]] ; then
savedir=$(pwd)
cd $fname
dodir $savedir/$fname
cd $savedir
fi
done
return
}
dodir $(pwd)
exit 0