Unix/Linux - How do I check existence of a specific link, then fix it

(imported topic written by SystemAdmin)

CBCibmlab02:/

root # ls -l /usr/bin/perl

lrwxrwxrwx 1 root system 29 Dec 01 08:29 /usr/bin/perl -> …/…/opt/SNIperl585/bin/perl

I wat to check if the link /usr/bin/perl is linked to …/…/opt/SNIperl585/bin/perl

If not run “ln -s …/…/opt/SNIperl585/bin/perl /usr/bin/perl” from the /usr/bin directory

(imported comment written by NoahSalzman)

As way of an example, here are my files:

root@linuxbox ~

ls -l bar/*

lrwxrwxrwx 1 root root 10 Dec 8 00:05 bar/link1 -> foo/target

lrwxrwxrwx 1 root root 13 Dec 8 00:06 bar/link2 -> foo/badtarget

Here is what the Relevance looks like:

Q: value of symlink “/root/bar/link1” is “foo/target”

A: True

Q: value of symlink “/root/bar/link2” is “foo/target”

A: False

Also, if you are looking for other symlink operators…

Q: properties whose (it as string contains “symlink”)

A: socket file : socket file

A: fifo file : fifo file

A: device file : device file

A: name of : string

A: pathname of : string

A: location of : string

A: value of : string

A: value accessible of : boolean

A: parent folder of : folder

A: symlink : symlink

A: symlink of : symlink

A: symlink : symlink

A: file : file

A: folder : folder

A: device file : device file

A: fifo file : fifo file

A: socket file : socket file

A: symlink : symlink

A: modification time of : time

A: accessed time of : time

A: change time of : time

A: user name of : string

A: group name of : string

A: uid of : integer

A: gid of : integer

A: link count of : integer

A: symlinks of : symlink

A: ancestors of : folder

A: filesystem of : filesystem

A: drive of : filesystem

(imported comment written by SystemAdmin)

Works great… Thanks

Relevance:

Relevance expression is false value of symlink “/usr/bin/perl” contains “…/…/opt/SNIperl585/bin/perl”

Action:

// Fix Perl Link

wait sh -c “/usr/bin/rm /usr/bin/perl”

wait sh -c “/usr/bin/ln -s …/…/opt/SNIperl585/bin/perl /usr/bin/perl”

(imported comment written by NoahSalzman)

In reference to the “ln” command: you may want to make sure you are in the correct directory before running a command that has a relative path in it.