Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find symbolic links to the current file?

Tags:

php

perl

Is there a way in PHP or Perl to find all symbolic links to the current file?

like image 763
Eric Avatar asked Dec 08 '22 00:12

Eric


1 Answers

Without traversing the filesystem looking for all symbolic links and then checking their destination, no. But if you still want to do this, it's pretty straight-forward:

use strict;
use warnings;
use File::Find;

my $target = 'the filename you want to find links to';
finddepth(
    sub {
        return if not -l $File::Find::name;
        print "found $File::Find::name!\n" if readlink($File::Find::name) eq $target;
    },
    '/'
);
like image 158
Ether Avatar answered Dec 14 '22 23:12

Ether