perlfunc
gods
<P>
stat - get a file's status information
<P>
<HR>
<P>
stat
<FONT SIZE=-1>FILEHANDLE</FONT>
<P>
stat
<FONT SIZE=-1>EXPR</FONT>
<P>
stat
<P>
<HR>
<P>
Returns a 13-element list giving the status info for a file, either the file opened via
<FONT SIZE=-1>FILEHANDLE,</FONT> or named by
<FONT SIZE=-1>EXPR.</FONT> If
<FONT SIZE=-1>EXPR</FONT> is omitted, it stats
<CODE>$_</CODE>. Returns a null list if the stat fails. Typically used as follows:
<P>
<PRE> ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
$atime,$mtime,$ctime,$blksize,$blocks)
= stat($filename);
</PRE>
<P>
Not all fields are supported on all filesystem types. Here are the meaning
of the fields:
<P>
<PRE> 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 since the epoch
9 mtime last modify time since the epoch
10 ctime inode change time (NOT creation time!) since the epoch
11 blksize preferred block size for file system I/O
12 blocks actual number of blocks allocated
</PRE>
<P>
(The epoch was at 00:00 January 1, 1970
<FONT SIZE=-1>GMT.)</FONT>
<P>
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 or filetest are returned. Example:
<P>
<PRE> if (-x $file && (($d) = stat(_)) && $d < 0) {
print "$file is executable NFS file\n";
}
</PRE>
<P>
(This works on machines only for which the device number is negative under
<FONT SIZE=-1>NFS.)</FONT>
<P>
In scalar context, [perlfunc:stat|stat()] returns a boolean value indicating success or failure, and, if successful,
sets the information associated with the special filehandle <CODE>_</CODE>.
<HR>