Can anybody please tell me how can I determine whether a file is SYMBOLIC LINK, using the stat() function ?
So far I have this:
my @attrs = stat($fileName);
my $mode = $attrs[2];
What next ?
Can anybody please tell me how can I determine whether a file is SYMBOLIC LINK, using the stat() function ?
So far I have this:
my @attrs = stat($fileName);
my $mode = $attrs[2];
What next ?
For symbolic links, you should use lstat() to test rather than stat().
#!/usr/bin/perl -w
use Fcntl ":mode";
my @files = ("/etc/rc5.d/S99rc.local", "users.ini");
foreach (@files) {
my @attrs = lstat($_);
print (S_ISLNK($attrs[2])?"$_: Is a Link\n":"$_: Not a Link\n");
}