Quick One-liner
find /home/user/public_html/qa -type l -print0 | xargs -0 -n1 -P0 sh -c 'NEWLINK=$(readlink "$3" | sed -e "s|${1}|${2}|"); ln -snf "$NEWLINK" "$3";' _ "/dev/" "/qa/"
Shouldn't grab anything with
dev
orqa
in their name.
Explain
find PATH <PATH> -type l -print0
Find all links under PATH
xargs -0 -n1 -P0 CMD <CMD>
For every input (null delimited), run CMD
with 1 parameter, as parallel as possible
CMD = sh -c 'SCMD' '<SCMD>' _ "ARG1" "ARG2" ARG3
Run a shell SCMD
with arguments (3 in this case)
SCMD
NEWLINK=$(readlink "$3" | sed -e "s|${1}|${2}|");
ln -snf "$NEWLINK" "$3";
Get original link then modify with sed
using ARG1
and ARG2
.
Update link with new value.
Can be compressed to:
ln -snf $(readlink "$3" | sed -e "s|${1}|${2}|") "$3"
but then becomes less readable and could break with/some/path with spaces/here
in certain contexts