l i n u x - u s e r s - g r o u p - o f - d a v i s
L U G O D
 
Next Meeting:
April 21: Google Glass
Next Installfest:
TBD
Latest News:
Mar. 18: Google Glass at LUGOD's April meeting
Page last updated:
2004 Sep 21 19:01
#!/usr/bin/perl # david hummel 2004-05-27 # calculate total file size in bytes of file/dir arguments # if dir, recursively add up all files contained in it # symlinks are ignored # why?: because du reports block usage use strict; use warnings; $ARGV[0] = '.' unless @ARGV; foreach my $arg (@ARGV) { if (! -e $arg) { print "$arg doesn't exist\n"; } elsif (-l $arg) { } elsif (-f $arg && -r $arg) { my $size = (stat($arg))[7]; printf("%15lu $arg\n",$size); } elsif (-f $arg && ! -r $arg) { print "$arg isn't readable\n"; } elsif (-d $arg && -x $arg) { my $size = &dirsize($arg); printf("%15lu $arg\n",$size); } elsif (-d $arg && ! -x $arg) { print "$arg isn't accessible\n"; } } sub dirsize { my $dir = shift; my $size = 0; my $dirh; opendir($dirh,$dir) or return 0; while (my $entry = readdir($dirh)) { next if ($entry eq '.' || $entry eq '..'); $entry = "$dir/$entry"; if (-l $entry) { } elsif (-f $entry && -r $entry) { $size += (stat($entry))[7]; } elsif (-f $entry && ! -r $entry) { print "$entry isn't readable\n"; } elsif (-d $entry && -x $entry) { $size += &dirsize($entry); } elsif (-d $entry && ! -x $entry) { print "$entry isn't accessible\n"; } } closedir($dirh); return $size; }

LinkedIn
LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
facebook
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
O'Reilly and Associates
For numerous book donations.