Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > size per day of a directory

Reply
Thread Tools

size per day of a directory

 
 
George Bouras
Guest
Posts: n/a
 
      02-14-2013
it is simple but someone may find it useful

http://www.easybytez.com/73uhlur5mvgv


--
Using Opera's mail client: http://www.opera.com/mail/
 
Reply With Quote
 
 
 
 
George Bouras
Guest
Posts: n/a
 
      02-14-2013
here it is



#!/usr/bin/perl
# Show the data size per date
# data_per_day.pl /data/cache

use strict;
use warnings;
use File::Find;

my $dir = exists $ARGV[0] ? ( -d $ARGV[0] ? $ARGV[0] : die "Not existing
directory: $ARGV[0]\n" ) : ( die "Specify an existing directory as
argument\n" );
my %Info = ();
my @Month = qw/Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec/;

File::Find::find({wanted=>sub {
return unless -f $File::Find::name;
my $size = -s _;
my @Time = localtime( (stat _)[9] ); $Time[5]+=1900;
my $key = sprintf "%04d%02d%02d", @Time[5,4,3];
$Info{$key}->{'total files'}++ ;
$Info{$key}->{'total size'} += $size;
},no_chdir=>1, bydepth=>0, follow=>0}, $dir);

foreach my $date (sort {$a <=> $b} keys %Info) {
my ($y,$m,$d) = $date =~/^(\d{4})(\d\d)(\d\d)/;
print "$d $Month[$m] $y\n";
print "\ttotal files : $Info{$date}->{'total files'}\n";
print "\ttotal size : ", __Human_size( $Info{$date}->{'total size'} )
,"\n"
}

sub __Human_size {
if ( $_[0] < 1024 ) { return "$_[0] Bytes" }
elsif ( $_[0] < 1024**2 ) { return sprintf "%.1f Kb" , ($_[0]/(1024**1)) }
elsif ( $_[0] < 1024**3 ) { return sprintf "%.1f Mb" , ($_[0]/(1024**2)) }
elsif ( $_[0] < 1024**4 ) { return sprintf "%.2f Gb" , ($_[0]/(1024**3)) }
elsif ( $_[0] < 1024**5 ) { return sprintf "%.2f Tb" , ($_[0]/(1024**4)) }
elsif ( $_[0] < 1024**6 ) { return sprintf "%.2f Pb" , ($_[0]/(1024**5)) }
elsif ( $_[0] < 1024**7 ) { return sprintf "%.2f Eb" , ($_[0]/(1024**6)) }
else { return $_[0] }
}
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Now.day and day(now) returning the wrong day! Andy ASP .Net 1 11-06-2008 12:20 PM
Quick one - Is SESSION per browser instance or per IP Address? =?Utf-8?B?S01aX3N0YXRl?= ASP .Net 7 04-10-2006 03:38 AM
Per packet vs per flow routing R Siffredi Cisco 8 03-24-2005 06:33 PM
Per-to-Per is OK but no ICS Jens Mander Wireless Networking 4 01-23-2005 10:24 PM
Should i select per device or per server to do all exercises? ADRENALINE MCSE 20 01-22-2004 09:20 PM



Advertisments