Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to modify the following in order to rename some symbolic links:

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'\

Unfortunately the -lname option does not work for HPUX. Do you know something equivalent that I can use?

Just to give you and idea of my problem, I want to change all the symbolic links inside a particular folder.

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

Now folder "A" contains more than 100 different files having soft links which I need to change in this manner.

share|improve this question
Addressing a question to a particular user doesn't work. – Dennis Williamson Dec 27 '10 at 20:29
thanks for editing Dennis, as the script I was referring to was from David so mentioned his name. – kalpesh Dec 28 '10 at 12:43
hi All, my issue got resolved with the following solution "find . -type l -exec ll -a {} + | awk '{ print "ln -sf", $11, $9}' > script" – kalpesh Dec 28 '10 at 13:58

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
      link_to_change=$(echo "$link" | sed s/dev/qa/)
      ln -nsf "$(echo "$target" | sed s/dev/qa/)" "$link_to_change";;
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .