##########################################
#!/usr/bin/perl -w
#
use strict;
my $size = 0;
while(<>){
chomp;
next unless (-f $_);
my $file_size = -s $_;
$size += $file_size;
}
print "Total: $size\n";
Here, feed this filenames.
Yes, I can do it in 1 line in your AWK example. Or in Perl. But I won't unless required, very few people can read, understand, and then CHANGE one liners, so they are landmines waiting to be stepped on.
|
|
I dont quite get this
if I feed it filenames how does it determine the size?
If we torture the data long enough, it will confess. (Ronald Coase, Nobel Prize for Economic Sciences, 1991)
|
|
-s
Perl has most of the unix scripting test operators:
http://perldoc.perl....functions/-X.html This checks to see if it is a regular file and goes to the top of the current loop if not: next unless (-f $_); This declares a variable and assigns it the size of the filename contained in the default operator. my $file_size = -s $_; |
|
Ah, got it. thanx!
If we torture the data long enough, it will confess. (Ronald Coase, Nobel Prize for Economic Sciences, 1991)
|
|
That was all an inside joke, right?
There weren't enough characters there to actually do anything useful.
--
Drew |
|
no works as advertized
If we torture the data long enough, it will confess. (Ronald Coase, Nobel Prize for Economic Sciences, 1991)
|
|
Sigh
Must be pebkac.
Current dir: $ l total 12 -rwxr-xr-x 1 broom broom 162 2010-03-26 19:55 add_file_size.pl -rwxr-xr-x 1 broom broom 608 2010-03-26 19:55 make_self_contained.pl -rwxr-xr-x 1 broom broom 657 2010-03-26 19:55 maketests.pl Execute it: $ find . -print | ./add_file_size.pl Total: 1427 Figure what the sizes should be: $ bc bc 1.06 Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation, Inc. This is free software with ABSOLUTELY NO WARRANTY. For details type `warranty'. 162+608+657 1427 It matches. The script file contains the following: $ cat add_file_size.pl
|
|
sorry, no, works as advertized. My bad forgot comma
If we torture the data long enough, it will confess. (Ronald Coase, Nobel Prize for Economic Sciences, 1991)
|
|
Don't show it to Ben.
He'd do it in one line. More line noise than characters. And it would be brilliant.
|