stat EXPR

Returns a 13-element list giving the status info for a file, either the file opened via FILEHANDLE or DIRHANDLE, or named by EXPR. If EXPR is omitted, it stats $_ (not _!). Returns the empty list if stat fails. Typically used as follows:

FILEHANDLE ��� DIRHANDLE �����������⓾�ŝ�若����潟�������⓾����������<�ゃ�˨����� EXPR ��ф��絎���������������<�ゃ�˨�勖����宴��筝����������13 荀�膣���勉�ŝ�鴻�����菴������障����� EXPR ��������ャ�������������� $_ �����������������障�� (_ ��с�壔�������障�����!)��� stat ���紊掩����������翫����˨�壔��腥冴�ŝ�鴻�����菴������障����� ��勰����壔��篁ヤ����勉�������˨����☖戎�����障��:

    my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
           = stat($filename);

Not all fields are supported on all filesystem types. Here are the meanings of the fields:

�����⓾�勉����<�ゃ�˨�激�鴻�������у����⓾�勉����c�若�˨�����絲上�������⓾�������������с�壔�������障�������� �����c�若�˨����勖����潟�壚札筝���勰�������с�����

  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 I/O size in bytes for interacting with the
             file (may vary from file to file)
 12 blocks   actual number of system-specific blocks allocated
             on disk (often, but not always, 512 bytes each)
  0 dev      �����<�ゃ�˨�激�鴻�������勉�������ゃ�合�ɱ
  1 ino      inode ��ɱ
  2 mode     �����<�ゃ�˨�≪�若�� (��帥�ゃ����������若�������激�с��)
  3 nlink    �����<�ゃ�˨�吾��(�����若��)��ŝ�潟�壔�勖�
  4 uid      �����<�ゃ�������������勉�⓾�若�吟�� ID ��勖�医�
  5 gid      �����<�ゃ�������������勉�違�˨�若�� ID ��勖�医�
  6 rdev     ��������ゃ�壕����ュ��(��号�������<�ゃ�˨�勉��)
  7 size     �����<�ゃ�˨�泣�ゃ��(�����ゃ�����篏�)
  8 atime    膣����������������緇���˨�≪�壔�祉�鴻�������������祉�障�с�勛����
  9 mtime    膣����������������緇���˩信罩�(modify)��������������祉�障�с�勛����
 10 ctime    膣�������������inode 紊����(change)��������������祉�障�с�勛����� (*)
 11 blksize  �����<�ゃ�˨����勛�娯��篏������勉�������̹�í����� I/O �����ゃ����
 12 blocks   �����c�鴻�壔����蚊��綵���⓾����激�鴻�����箴�絖���勉����㏍�����(絽吾�˨�с�
             ��������障����������������⓾����壔����������� 512 �����ゃ��)��勖�

(The epoch was at 00:00 January 1, 1970 GMT.)

(膣������� GMT ��� 1970/01/01 00:00:00���)

(*) Not all fields are supported on all filesystem types. Notably, the ctime field is non-portable. In particular, you cannot expect it to be a "creation time"; see "Files and Filesystems" in perlport for details.

(*) �����⓾�勉����c�若�˨����������⓾�勉����<�ゃ�˨�激�鴻�������帥�ゃ����у嚳綽������⓾�������������с� ��������障�������� �����������˨��ctime ��勉����c�若�˨����夌Щ罎���с����������障�������� ��鴻�˨�����������������篏���������祉�������喝����������������壠�堺�ャ�障�����; 荅括完��˨�ゃ����⓾�� "Files and Filesystems" in perlport ��������с����⓾��������������

If stat is passed the special filehandle consisting of an underline, no stat is done, but the current contents of the stat structure from the last stat, lstat, or filetest are returned. Example:

筝�膩���������� _ �����������劫�ャ�ŝ����<�ゃ�˨����潟����˨�� stat �� 羝<��������絎������˨�� stat ���茵���ŝ��������stat 罕����篏����罧���c�⓾����� ��������� stat, lstat ��� �����<�ゃ�˨����鴻����勖����宴��菴���������障����� 箴�:

    if (-x $file && (($d) = stat(_)) && $d < 0) {
        print "$file is executable NFS file\n";

(This works on machines only for which the device number is negative under NFS.)

(��������壔��NFS ��勉�������с�������ゃ�合�ɱ垩��莢���˨�ŝ�������激�潟�с�勉�水��篏������障�����)

On some platforms inode numbers are of a type larger than perl knows how to handle as integer numerical values. If necessary, an inode number will be returned as a decimal string in order to preserve the entire value. If used in a numeric context, this will be converted to a floating-point numerical value, with rounding, a fate that is best avoided. Therefore, you should prefer to compare inode numbers using eq rather than ==. eq will work fine on inode numbers that are represented numerically, as well as those represented as strings.

筝������勉����í����������í�若����с�壔��inode ��ɱ垩�� perl �����贋�医�ゃ������� ��宴����鴻����ャ�c�⓾����������勉��������紊с����������˨�ŝ�c�⓾����障����� ������綽�荀���ŝ�����inode ��ɱ垩�壔����ゅ��篏����篆�絖���������������� 10 ��我��絖������������ 菴���������障����� ��医�ゃ�潟�潟����㏍�鴻����т戎�����������������壚幻������篌眼��羌勐��絨���亥�号�違��紊������������� ��с�������������帥�������鴻��腟������˨�ŝ����障����� 緇���c�⓾��inode ��ɱ垩�勖��莠���˨�� == ��с�壔�ŝ�� eq ���篏帥����鴻����с����� eq ��壔��inode ��ɱ垩����医�ゃ�ц;�憗�������⓾����⓾��������絖������ц;�憗�������⓾����⓾�� �����障�����篏������障�����

Because the mode contains both the file type and its permissions, you should mask off the file type portion and (s)printf using a "%o" if you want to see the real permissions.

��≪�若����˨�壔����<�ゃ�˨�帥�ゃ����������勖┤�����勌検��鴻����˨�障����⓾�������勉�с�� ��㋚����勖┤������荀���������翫����壔��(s)printf ��� "%" ���篏帥���������� �����<�ゃ�˨�帥�ゃ����������鴻�壔�������鴻����с�����

    my $mode = (stat($filename))[2];
    printf "Permissions are %04o\n", $mode & 07777;

In scalar context, stat returns a boolean value indicating success or failure, and, if successful, sets the information associated with the special filehandle _.

��鴻�˨�í�潟�潟����㏍�鴻����с�壔��stat ��壩��������紊掩�����茵���������遵�ゃ�� 菴���������������������翫����壔����劫�ャ�ŝ����<�ゃ�˨����潟����� _ ��̥����割�������������� �����宴����祉����������障�����

The File::stat module provides a convenient, by-name access mechanism:

File::stat ��≪�吾�ャ�若�˨�壔��箴水�í�ɱ�������˨�������≪�壔�祉�号��罕�������箴������障�����

    use File::stat;
    my $sb = stat($filename);
    printf "File is %s, size is %s, perm %04o, mtime %s\n",
           $filename, $sb->size, $sb->mode & 07777,
           scalar localtime $sb->mtime;

You can import symbolic mode constants (S_IF*) and functions (S_IS*) from the Fcntl module:

��≪�若��絎���� (S_IF*) ��◒�∽�� (S_IS*) ��� Fcntl ��≪�吾�ャ�若�˨����� ��ゃ�潟����若����с����障�����

    use Fcntl ':mode';

    my $mode = (stat($filename))[2];

    my $user_rwx      = ($mode & S_IRWXU) >> 6;
    my $group_read    = ($mode & S_IRGRP) >> 3;
    my $other_execute =  $mode & S_IXOTH;

    printf "Permissions are %04o\n", S_IMODE($mode), "\n";

    my $is_setuid     =  $mode & S_ISUID;
    my $is_directory  =  S_ISDIR($mode);

You could write the last two using the -u and -d operators. Commonly available S_IF* constants are:

���緇���勌����ゃ�� -u ��� -d 羲�膊�絖����篏帥�c�⓾����吾����障����� 筝���㋘����ñ���櫝�純�� S_IF* 絎���違�壚札筝���勉����勉�с�����

    # Permissions: read, write, execute, for user, group, others.


    # Setuid/Setgid/Stickiness/SaveText.
    # Note that the exact meaning of these is system-dependent.


    # File types.  Not all are necessarily available on
    # your system.


    # The following are compatibility aliases for S_IRUSR,
    # S_IWUSR, and S_IXUSR.


and the S_IF* functions are

筝���㋘����ñ���櫝�純�� S_IF* ��∽�違�壚札筝���勉����勉�с�����

    S_IMODE($mode)    the part of $mode containing the permission
                      bits and the setuid/setgid/sticky bits

    S_IFMT($mode)     the part of $mode containing the file type
                      which can be bit-anded with (for example)
                      S_IFREG or with the following functions

    # The operators -f, -d, -l, -b, -c, -p, and -S.

    S_ISREG($mode) S_ISDIR($mode) S_ISLNK($mode)
    S_ISBLK($mode) S_ISCHR($mode) S_ISFIFO($mode) S_ISSOCK($mode)

    # No direct -X operator counterpart, but for the first one
    # the -g operator is often equivalent.  The ENFMT stands for
    # record flocking enforcement, a platform-dependent feature.

    S_ISENFMT($mode) S_ISWHT($mode)

See your native chmod(2) and stat(2) documentation for more details about the S_* constants. To get status info for a symbolic link instead of the target file behind the link, use the lstat function.

S_* 絎���違�̹�≪�����荅括完��˨�ゃ����⓾�壔����ゃ����c����� chmod(2) ��� stat(2) �� �����㏍�ャ�<�潟����������с����⓾�������������� ��ŝ�潟�壔�勐����˨����������<�ゃ�˨�с�壔�ŝ�������激�潟����ŝ����壔�ŝ�潟�壔����勉����勉�勖����宴�� 緇���������翫����壔��lstat ��∽�違��篏帥�c�⓾��������������

Portability issues: "stat" in perlport.

腱紙����с�勐�馹�: "stat" in perlport���