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 '/*' ... 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. 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. Have a nice day, Berny -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org