[PLUG] Tracing back symlinks

Randal L. Schwartz merlyn at stonehenge.com
Wed May 29 21:38:44 UTC 2002


>>>>> "Ed" == Ed Sawicki <ed at alcpress.com> writes:

Ed> Given a normal file that has symbolic links pointing to it, is
Ed> there a way to list all the links (the aliases pointing to the
Ed> normal file)?

    #!/usr/bin/perl

    use File::Find;

    my ($target_dev, $target_ino) = stat shift or die "Cannot stat";
    @ARGV = qw(/) unless @ARGV;
    find sub {
      return unless my ($dev, $ino) = stat;
      return unless $dev == $target_dev and $ino == $target_ino;
      print $File::Find::name, "\n";
    }, @ARGV;

There ya go.  First arg is the file to be located. But it'll be slow,
because you have to look at EVERY file.  If you wanna narrow down the
search, add a second argument.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn at stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!



More information about the PLUG mailing list