#!/bin/ksh #Find every symbolic link leading to $1. if [[ $# -ne 1 ]] then echo $0: arg is file to search for 1>&2 exit 1 fi find / -type l -ls 2> /dev/null | #lowercase L, minus lowercase LS perl -ane ' $target = $F[$#F]; #last field if ($target !~ m:^/:) { #if $target is a relative pathname $name = $F[$#F - 2]; #3rd from last field is name of symb link $name =~ s:[^/]+$::; #remove rightmost word $target = $name . $target; #now target is full pathname } $target =~ s:/(\.?/)*:/:g; while ($target =~ s:/[^/]+/*\.\.::g) { } if ($target eq "'$1'") { print $_; #$_ is the current line of input. } ' exit 0