in reply to How to find folder size

-s returns the size of a file (even if that file is a directory). If you want to sum the sizes of the files within a directory then you'll probably want something like File::Find.


See the Copyright notice on my home node.

Perl training courses

Replies are listed 'Best First'.
Re^2: How to find folder size
by spx2 (Deacon) on Jul 08, 2009 at 06:11 UTC
    or you can just parse output of du -csh <directory>
      Not very portable though - better to stick to davorg solution.
        Note that davorg suggested using -s, which for a directory tells you the size of the directory entry itself - which grows (but in many filesystems doesn't shrink) with the number of files. The size reported does not have any relation at all with the sum of the sizes of the files inside a directory. Which to me, seems what the OP wants.

        Note that even using -s to sum the sizes of the files in a directory has its problems - you have consider symlinks and hardlinks. The former may cause loops, or point to a totally different part of the filesystem, while hardlinks may cause you to count files two or more times if you aren't tracking inodes.