in reply to du and -s

Most filesystems store files as set of blocks. So even if your file has only one byte phisically it takes one block on the disk.

To reflect this fact some programs report file sizes in blocks. For example:

# creating two bytes long file bash-2.05b$ echo 1 > test # ls -l reports logical size of file bash-2.05b$ ls -l test -rw-r--r-- 1 ilya ilya 2 Jul 24 15:25 test # du -b reports physical size of file # (4096 - size of block on my filesystem) bash-2.05b$ du -b test 4096 test

Perl's -s reports logical file size like ls -l This is why its results doesn't match du results.

Update: BTW size of blocks depends on filesystem so in general tye's solution is incorrect. There are exist module Filesys::Statvfs which allows to query filesystem for size of blocks.

--
Ilya Martynov (http://martynov.org/)