The value exposed in (stat _)[11]
is st_blksize
, which is documented as
A hint as to the "best" unit size for I/O operations. This field is not defined for block special or character special files.
This is not necessarily the block size of the particular filesystem on which your file resides, but the same manual page contains a convenient definition:
blkcnt_t st_blocks; /* Number of 512 byte blocks allocated*/
So you could use code such as
#! /usr/bin/perl
use warnings;
use strict;
sub usage { "Usage: $0 file ..\n" }
die usage unless @ARGV;
foreach my $file (@ARGV) {
my $dir = dirname $file;
my $blocks = (stat $file)[12];
unless (defined $blocks) {
warn "$0: stat $file: $!\n";
next;
}
print "$file - ", $blocks * 512, "\n";
}
If you're concerned that the block sizes of your filesystems aren't multiples of 512, double-check with either
df -g <directory>
or if you have root
fstyp -v /dev/dsk/...
For an ordinary file, the size of the file itself, i.e., (stat _)[7]
, is usually smaller than the total size of all blocks allocated because filesystems allocate whole blocks.