in reply to Unix size again
in thread Unix size

Use File::Find:
#!/usr/bin/perl -l use strict; use warnings; use File::Find; my $size = 0; find( sub { $size += -f $_ ? -s _ : 0 }, shift(@ARGV)); $size = sprintf( "%.02f", $size / 1024 / 1024); print "$size MB"; __END__ returned: 110.11 MB for /etc

Replies are listed 'Best First'.
Re^2: Unix size again
by JavaFan (Canon) on Feb 08, 2012 at 08:49 UTC
    That's wrong.

    Your solution counts files multiple times if there are multiple links to a file. OTOH, you are not counting the size of directories themselves. (Even an empty directory has typically a size of 4096 bytes).

    du takes care of both things.