Jesper Noehr wrote:
> 
> Hey list.

Hello,

> I'm having a problem reading the size of a directory with recursive
> directories.
> The problem is that du -s shows a different bytecount than my program does.

$ man du

NAME
       du - estimate file space usage

SYNOPSIS
       du [OPTION]... [FILE]...

DESCRIPTION
       Summarize  disk usage of each FILE, recursively for direc­
       tories.


> Here's my code:
> 
> #!/usr/gnu/bin/perl -w
> use File::Find;
> @ARGV = ('.') unless @ARGV;
> my $sum = 0;
> find sub { $sum += -s }, @ARGV;
> print "@ARGV contains $sum bytes\n";
> 
> 'du' shows a size of ~120 megabytes, while the program shows a size of
> something that's waaay larger.
> 
> Any idea why?

du looks at disk space usage while your program looks at file sizes.  If
your disk has a block size of 1024 and you have a file that is 10 bytes
in size, du will report the amount of space based on the blocks required
to store the file, not on the actual size of the file.

$ ls -l test.txt
-rw-r--r--    1 john     users         187 Jul  9 11:54 test.txt
$ perl -le'print +(lstat shift)[11]' test.txt
4096
$ du -b test.txt
4096    test.txt
$ du test.txt
4       test.txt



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to