The stat and lstat Functions
While these file tests are fine for testing various attributes
regarding a particular file or filehandle, they don’t tell the whole
story. For example, there’s no file test that returns the number of
links to a file or the owner’s user ID (uid). To get at the remaining
information about a file, merely call the stat function, which
returns pretty much everything
that the stat Unix system call returns (hopefully more than you want to
know).[*] The operand to stat is
a filehandle (including the _ virtual
filehandle), or an expression that evaluates to a filename. The return
value is either the empty list, indicating that the stat failed (usually because the file doesn’t
exist), or a 13-element list of numbers, most easily described using the
following list of scalar variables:
my($dev, $ino, $mode, $nlink, $uid, $gid, $rdev,
$size, $atime, $mtime, $ctime, $blksize, $blocks)
= stat($filename);The names here refer to the parts of the stat structure, described in detail in the
stat(2) manpage. You should probably look there for
the detailed descriptions. But in short, here’s a quick summary of the
important ones:
- $dev and $ino
The device number and inode number of the file. Together they make up a “license plate” for the file. Even if it has more than one name (hard link), the combination of device and inode numbers should always be unique.
- $mode
The set of permission bits for the file, and some other bits. If you’ve ever used the Unix command ls -l to get a detailed ...