#!/usr/local/bin/perl -w ## ## Takes a path and tells you the symlinks involved in traversing it. E.g: ## ## ---------------------------------------------------------------------- ## % links ~/l/cemacs ## 1 /afs -> afs.test ## 2 /afs/cs.utah.edu/home/lomew -> ../user/6/lomew ## 3 /afs/cs.utah.edu/home/lomew/l/cemacs -> /usr/local/share/contrib/lib/xemacs-19.14 ## 4 /usr/local/share -> /server/afs/hp700_bsd/usr/local/share ## 5 /server -> usr/nserver ## 6 /server/afs -> ../nnserver/afs ## 7 /usr/local/share/contrib -> /afs/cs.utah.edu/hp700_bsd/usr/local/share/contrib ## 8 /afs -> afs.test ## ---------------------------------------------------------------------- ## ## Author: Bart Robinson - July 29, 1996 ## $Id: linkx,v 1.3 1996-12-07 20:42:04-07 lomew Exp $ ## $debug = 0; $path = shift; die "usage: $0 path\n" unless defined($path); $count = 0; countlinks($path, 0); sub dirname { my $f = shift; $f =~ s-/[^/]*$--; return $f; } sub countlinks { my ($path, $indent) = @_; my @elems = split('/', $path); my $p = $elems[0] eq "" ? "" : "."; # $elems[0] is "" for abs path my $elem; print "-- ($indent) checking $path\n" if $debug; foreach $elem (@elems) { next if $elem eq ""; $p .= "/$elem"; print "-- ($indent) -------- $p\n" if $debug; next unless -l $p; ++$count; $l = readlink($p); printf("%2d %s%s -> %s\n", $count, " " x $indent, $p, $l); unless ($l =~ m-^/-) { ## Relative path. chdir dirname($p) or die "$p: $!"; # $l = dirname($p) . "/" . $l; } countlinks($l, $indent+1); } }