stat
功能?或者您可能需要lstat
获取链接信息,或readlink
读取符号链接指向的名称。
示例stat
和lstat
工作:
$ echo "Petunia" > user.hostname.com-22222
$ ln -s user.hostname.com-22222 SingletonLock
$ ls -l user.* Singl*
lrwxr-xr-x 1 jleffler staff 23 Sep 26 20:24 SingletonLock -> user.hostname.com-22222
-rw-r--r-- 1 jleffler staff 8 Sep 26 20:24 user.hostname.com-22222
$ cat stat.pl
#!/usr/bin/env perl
use strict;
use warnings;
my @names = ( "user.hostname.com-22222", "SingletonLock" );
foreach my $file (@names)
{
my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
$atime,$mtime,$ctime,$blksize,$blocks)
= lstat $file;
printf "lstat: %2d (%.5o) - %s\n", $size, $mode, $file;
($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
$atime,$mtime,$ctime,$blksize,$blocks)
= stat $file;
printf "stat: %2d (%.5o) - %s\n", $size, $mode, $file;
}
$ perl stat.pl
lstat: 8 (100644) - user.hostname.com-22222
stat: 8 (100644) - user.hostname.com-22222
lstat: 23 (120755) - SingletonLock
stat: 8 (100644) - SingletonLock
$