当前位置:首页 » Perl » Perl lstat()函数

Perl lstat()函数

perl lstat()函数例子,lstat()函数学习,lstat()函数实例代码,lstat()函数在线教程等

语法

lstat FILEHANDLE

lstat EXPR

lstat


定义和用法

执行相同的测试FILEHANDLE状态函数或文件所提到的EXPR或$_

如果该文件是一个符号链接,它返回的信息的链接,而不是它指向的文件。 否则,它返回的信息的文件。

返回值

  • 在列表上下文中,它返回一个列表中13种元素,这些个行业如下:

  0 dev      device number of filesystem
  1 ino      inode number
  2 mode     file mode  (type and permissions)
  3 nlink    number of (hard) links to the file
  4 uid      numeric user ID of file's owner
  5 gid      numeric group ID of file's owner
  6 rdev     the device identifier (special files only)
  7 size     total size of file, in bytes
  8 atime    last access time in seconds since the epoch
  9 mtime    last modify time in seconds since the epoch
 10 ctime    inode change time in seconds since the epoch (*)
 11 blksize  preferred block size for file system I/O
 12 blocks   actual number of blocks allocated

注: 时代是在1970年1月1日00:00 GMT。

例子

试试下面的例子:

#!/usr/bin/perl -w
#by www.gitbook.net

$filename = "/tmp/test.pl";
($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
     $atime,$mtime,$ctime,$blksize,$blocks)
           = lstat($filename);
 printf "File is %s,\n size is %s,\n perm o, mtime %s\n",
        $filename, $size, $mode & 07777,
        scalar localtime $mtime;

这将产生以下结果:

File is /tmp/test.pl,
size is  202,
perm 007, mtime Wed Dec 31 17:00:00 1969