Le 23/08/2020 à 18:41, Bernhard Voelker a écrit :
On 2020-08-21 08:58, jdd@dodin.org wrote:
I need some sort of, but this code is not working ($j and $i are identical - my bash knowledge is bad :-(
#!/bin/sh for i ; do j=$(readlink $i) ; k=sed -i 's///run/media/jdd/intenso5to2/../..//g' $j ; ln -sf $k $i ; done
The task is 3-fold:
1. find symlinks with non-relative targets. 'find' can do that with: find -type l -lname '/*' ...
I don't need this part, I know where they are :-) (but it don't hurt :-)
2. Determine the link target and change only those with an existing target (a link target can contain arbitrary information). The 'readlink' tool does that with the -e option.
I know them as well
3. Create the same symlink in place with a relative target. 'ln' has the '-r' (--relative) option, and -f to remove the existing link.
This boils down to e.g.:
find . -type l -lname '/*' \ -execdir \ sh -c 'rel=$( readlink -e "{}" ) && ln -sfrv "$rel" "{}" ' \ \;
find will pass the link names where "{}" is mentioned in the above. Instead of having the shell code as -execdir argument one could of course also put it into a separate script.
No warranty - if you want to use it, then please test in a separate directory hierarchy first whether the result is what you want/need.
easy, I will test it, thanks jdd -- http://dodin.org -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org