ap0calypse has asked for the wisdom of the Perl Monks concerning the following question:

hi,

I'm experiencing a little problem here I can't figure out on my own, so I'm asking you guys if you could give me a hint.

I already found filesys::df or filesys::diskusage on cpan but I'm asking myself if there is a way to get these statistics for a linux box just using perl internals. I don't really want to use "df" or "du" for retrieving the needed information. I know, it may seem pedantic, but I really want to do it this way.

Does anyone know how?

  • Comment on disk usage statistics with perl internals?

Replies are listed 'Best First'.
Re: disk usage statistics with perl internals?
by moritz (Cardinal) on Nov 23, 2010 at 16:33 UTC
Re: disk usage statistics with perl internals?
by Khen1950fx (Canon) on Nov 23, 2010 at 22:35 UTC
    Filesys::DiskSpace will do what you want. It doesn't use df or du. It uses a sub that uses syscall.
    #!/usr/bin/perl use strict; use warnings; use Filesys::DiskSpace; use Data::Dumper::Concise; my $dir = '/'; print Dumper( my($fs_type, $fs_desc, $used, $avail, $fused, $favail) = df $dir);
Re: disk usage statistics with perl internals?
by fisher (Priest) on Nov 23, 2010 at 16:55 UTC
    AFAIK df(1) uses statfs(2). Look above for perl function syscall
    As of du(1), you can recursively dive into subject directory and summarize all files found.