V
V
Viktor Taran2019-11-06 15:13:32
bash
Viktor Taran, 2019-11-06 15:13:32

How to bulk replace a symlink?

find /etc/nginx/bx -type l -name '*ks10.ks10.ru*' | sed -e 'p;s/ks10.ks10.ru/ks11.ks11.ru/g' | xargs -n2 mv

Renaming the file itself works, but not the links in it, so you need to replace the link itself, how to do this?
5dc2b98c41158071378547.jpeg

Answer the question

In order to leave comments, you need to log in

2 answer(s)
H
hint000, 2019-11-06
@hint000

find /etc/nginx/bx -type l -name '*ks10.ks10.ru*' | xargs ls -l | awk '{print $11, $9}' | sed -e 's/ks10.ks10.ru/ks11.ks11.ru/g' | xargs -n2 ln -s

At the same time, old symlinks are not deleted, only new ones are created; but it will not be difficult for you to remove the old ones.
And the solution is not universal - it should work for symlinks with absolute paths, but not with relative ones (it’s more difficult there, you have to parse the paths and separately take into account two points in them, in general, I’m lazy). But you seem to have absolute paths in symlinks.
Upd. sergey kuzmin in the comments suggested a wonderful readlink command, which, with the -f option, should immediately give out the full path via the symlink, so that universality can be achieved without complication.

S
SOTVM, 2019-11-06
@sotvm

man rename

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question