This bash command should do it for you:
find /home/user/public_html/qa/ -type l -lname '/home/user/public_html/dev/*' -printf 'ln -nsf "$(readlink "%p" | sed s/dev/qa/)" "$(echo "%p" | sed s/dev/qa/)"\n' > script.sh
It uses find
to identify all files in the qa
directory that are symbolic links with a target that's in the dev
directory, and for each one, it prints out a bash command that will replace the link with a link to the equivalent path in qa/
. After you run this, just execute the generated script with
bash script.sh
You might want to examine it manually first to make sure it worked.
Here's a more verbose version of the above find
command broken up on to multiple lines for easier viewingreading (though I wouldn't necessarily write it this way in practice):
SRC_DIR=SRC_DIR="/home/user/public_html/qa/qa"
OLD_TARGET=OLD_TARGET="/home/user/public_html/dev/dev"
SED_SCRIPT=sSUB="s/dev/qa/"
find $SRC_DIR -type l \
-lname "$OLD_TARGET*""$OLD_TARGET/*" -printf \
'ln -nsf "$(readlink "%p"|sed '$SED_SCRIPT'$SUB)" "$(echo "%p"|sed '$SED_SCRIPT'$SUB)"\n'\
> script.sh