Аналогичный код-пример на perl
#!/usr/bin/perl
$find_dir = '.';
$to_dir = '/tmp/test';
foreach(glob("$find_dir/*"))
{
print "checking $_ \n";
$link_path = readlink($_);
if($link_path ne '')
{
print "..found symlink $link_path \n";
if($link_path =~ /^$to_dir/)
{
print "....found matched symlink!\n";
# do something ...
# for example delete found file
# unlink($link_path)
}
}
}
На тестовой папке с содержимым
drwxrwxr-x 2 dt dt 4096 сен 16 12:08 1
lrwxrwxrwx 1 dt dt 4 сен 16 12:18 2 -> /tmp
lrwxrwxrwx 1 dt dt 9 сен 16 12:18 3 -> /tmp/test
lrwxrwxrwx 1 dt dt 18 сен 16 12:19 4 -> /tmp/test/test.txt
lrwxrwxrwx 1 dt dt 29 сен 16 12:19 5 -> '/tmp/test/tes test test 2.txt'
lrwxrwxrwx 1 dt dt 29 сен 16 12:19 'tes test test 2.txt' -> '/tmp/test/tes test test 2.txt'
-rwxr-xr-x 1 dt dt 387 сен 16 12:22 test.pl
Выдает следующее:
checking ./1
checking ./2
..found symlink /tmp
checking ./3
..found symlink /tmp/test
....found matched symlink!
checking ./4
..found symlink /tmp/test/test.txt
....found matched symlink!
checking ./5
..found symlink /tmp/test/tes test test 2.txt
....found matched symlink!
checking ./tes test test 2.txt
..found symlink /tmp/test/tes test test 2.txt
....found matched symlink!
checking ./test.pl