Symbolische Linkänderung für HP Unix

1214
kalpesh

Ich versuche, Folgendes zu ändern, um einige symbolische Links umzubenennen:

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 

Leider -lnamefunktioniert die Option für HPUX nicht. Wissen Sie etwas Äquivalent, das ich verwenden kann?

Um Ihnen nur einen Eindruck von meinem Problem zu vermitteln, möchte ich alle symbolischen Links in einem bestimmten Ordner ändern.

New Symbolic link --> /base/testusr/scripts  Old Symbolic link --> /base/produsr/scripts 

Der Ordner "A" enthält jetzt mehr als 100 verschiedene Dateien mit Softlinks, die ich auf diese Weise ändern muss.

2
Das Ansprechen einer Frage an einen bestimmten Benutzer funktioniert nicht. Dennis Williamson vor 13 Jahren 0
Danke für die Bearbeitung von Dennis. Das Skript, auf das ich mich bezog, war von David, der seinen Namen genannt hat. kalpesh vor 13 Jahren 0
Hallo zusammen, mein Problem wurde mit der folgenden Lösung gelöst: "find. -type l -exec ll -a {} + | awk ''> script" kalpesh vor 13 Jahren 0

1 Antwort auf die Frage

1
Gilles

With only POSIX tools, the only way to see the target of a symbolic link is through ls. The Linux and BSD readlink command is unfortunately not standard.

Using ls is brittle because you have to parse out the file names. Assuming that your file names do not contain newlines and that the targets of the symlinks do not contain the substring ->, the command ls -l "$link" | sed 's/.* -> //' prints the target of the link.

find /home/user/public_html/qa/ -type l | while IFS= read -r link; do target=$(ls -l "$link" | sed 's/.* -> //') case $target in /home/user/public_html/dev/*) link_to_change=$(echo "$link" | sed s/dev/qa/) ln -nsf "$(echo "$target" | sed s/dev/qa/)" "$link_to_change";; esac done