rendler has asked for the wisdom of the Perl Monks concerning the following question:
Someone asked a question yesterday on how he could go about replacing du(1) with perl. The answer I gave him was perl -MFile::Find -le 'find( sub { $size += -s }, "."); print $size'. He went away happy, but then half an hour later came back and said the the result returned by that was not the same as that of du(1). So after a little tweaking and testing I came to the very clear conclusion that I really didn't understand why it was doing what it was.
I came on here and asked in the chatterbox, and got some very good responses including one from tye but the problem was it all went over the top of my head and I basically didn't understand any of what he was explaining :(
Along with the explanation tye came up with this little bit of code perl -MFile::Find -le 'find( sub { $size += int( (511 + -s $_)/512 ) }, "."); print 512*$size' which is meant to produce results closer to du(1).
When I also went to test it on files with du -b * the filesizes returned by it was also not the same as that returned by -s or from ls -l.
So if anyone could please explain it into newbie terms I would be greatly appreciative. Thanks.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: du and -s
by IlyaM (Parson) on Jul 24, 2002 at 11:30 UTC | |
|
Re: du and -s
by Abigail-II (Bishop) on Jul 24, 2002 at 11:36 UTC | |
by grinder (Bishop) on Jul 24, 2002 at 13:14 UTC | |
|
Re: du and -s
by jmcnamara (Monsignor) on Jul 24, 2002 at 11:46 UTC | |
|
Re: du and -s
by rendler (Pilgrim) on Jul 25, 2002 at 08:32 UTC | |
by IlyaM (Parson) on Jul 25, 2002 at 10:22 UTC |