Filesys::DiskUsage - Estimate file space usage (similar to `du`)
use Filesys::DiskUsage qw/du/; # basic $total = du(qw/file1 file2 directory1/);
or
# no recursion $total = du( { recursive => 0 } , <*> );
# max-depth is 1 $total = du( { 'max-depth' => 1 } , <*> );
# get an array @sizes = du( @files );
# get a hash %sizes = du( { 'make-hash' => 1 }, @files_and_directories );
Estimate file space usage.
Get the size of files:
$total = du(qw/file1 file2/);
Get the size of directories:
$total = du(qw/file1 directory1/);
Follow symbolic links. Default is 0. Overrides symlink-size.
symlink-size
Get the size of a directory, recursively, following symbolic links:
$total = du( { dereference => 1 } , $dir );
Exclude files that match PATTERN.
Get the size of every file except for dot files:
$total = du( { exclude => qr/^\./ } , @files );
Return sizes in human readable format (e.g., 1K 234M 2G)
$total = du ( { 'human-readable' => 1 } , @files );
Return sizes in human readable format, but use powers of 1000 instead of 1024.
$total = du ( { 'Human-readable' => 1 } , @files );
Return the results in a hash.
%sizes = du( { 'make-hash' => 1 } , @files );
Sets the max-depth for recursion. A negative number means there is no max-depth. Default is -1.
Get the size of every file in the directory and immediate subdirectories:
$total = du( { 'max-depth' => 1 } , <*> );
Sets whether directories are to be explored or not. Set to 0 if you don't want recursion. Default is 1. Overrides max-depth.
max-depth
Get the size of every file in the directory, but not directories:
$total = du( { recursive => 0 } , <*> );
All file sizes are rounded up to a multiple of this number. Any file that is not an exact multiple of this size will be treated as the next multiple of this number as they would in a sector-based file system. Common values will be 512 or 1024. Default is 1 (no sectors).
$total = du( { sector-size => 1024 }, <*> );
Shows warnings when trying to open a directory that isn't readable.
$total = du( { 'show-warnings' => 0 }, <*> );
1 by default.
Symlinks are assumed to be this size. Without this option, symlinks are ignored unless dereferenced. Setting this option to 0 will result in the files showing up in the hash, if make-hash is set, with a size of 0. Setting this option to any other number will treat the size of the symlink as this number. This option is ignored if the dereference option is set.
make-hash
dereference
$total = du( { symlink-size => 1024, sector-size => 1024 }, <*> );
Human readable formats decimal places are truncated by the value of this option. A negative number means the result won't be truncated at all. Default if 2.
Get the size of a file in human readable format with three decimal places:
$size = du( { 'human-readable' => 1 , 'truncate-readable' => 3 } , $file);
Jose Castro, <cog@cpan.org>
<cog@cpan.org>
Copyright 2004 Jose Castro, All Rights Reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Filesys::DiskUsage, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Filesys::DiskUsage
CPAN shell
perl -MCPAN -e shell install Filesys::DiskUsage
For more information on module installation, please visit the detailed CPAN module installation guide.