[thelist] Re: Problem with the Unix 'du' command via perl script

Tony Frasketi webmaster at spacecovers.com
Tue Jun 17 14:45:14 CDT 2003

Thanks for all the suggestions folks! 

I had been trying to find the size of my entire web site by using the
'du -sb <my-home-directory>' command in a Perl script to be executed
from the Web. 

But I kept coming up with a diffence of 2,177,024 bytes between the
output of the 'du' command when executed from the Perl script from the
Web and when executed directly from the Unix command line.

   Output from 'su -sb' command from Perl script on Web:    83,250,176
   Output from 'su -sb' command from Unix Cmd Line:         85,427,200

2,177,024 bytes short from the Perl script.

I finally found the culprit that was causing the difference! I tracked
this exact byte difference to a particular directory buried in the
depths of my cgbin directory (it was an old directory that I no longer

The size of this directory was 2,177,024 bytes from the output of the
'du' command when issued from the Unix command line BUT ... was ZERO
bytes from the output of the 'du' command when issued from the Perl
script on the Web!

After I deleted this directory, the sizes of my entire website matched
when measured from the Web or from the Unix shell!!!

Again, thanks for your suggestions
Tony Frasketi

> Hello Dan
> Thanks for the response. I tried your suggestion but I still 
> get the differing sizes... So I'm still looking for a solution.
> > >    my($size) = `du -sb <directory-path>`;

>My suggetion just helped you get only the number of bytes it returned
>into $size instead of the 
>Bytes, whitespace, and directory that du returned.
>If you're getting different sizes try first to figure out what du is
>doing via command line on those directories.
>Is somthign running on the server that the size could fluxuate quickly
>in those directories?
> also man du 
>Perhaps an example of the same directory returning two results would
> > >
> > > However the differing results only occurs on some directories
> > > not on others.
> >
> > Probably because  du -sb is not retuneing an array like you seem
> > expect
> of the size then directory.
> > Try this:
> >
> >  my($size,$dir) = split(/\s+/,qx(du -sb $mydir));
> > # you don't have to have $dir
> > # sometimes you also need the entire path to program : 
> /usr/bin/du -sb 
> > # the qx is a better way to do backtick execution, just fyi
> >
> > HTH
> >
> > DMuey

More information about the thelist mailing list