du -dirs

Kevin Buettner kev@primenet.com
Thu, 22 Jun 2000 02:07:30 -0700


On Jun 22,  1:29am, Kevin Buettner wrote:

> Below another way to do it that doesn't use perl.
[...]
> find $1 -type f -not -type l -printf '%s\n' | awk -- '{s += $0} END {print s}'

Okay, I'm wasting way too much time on this, but I couldn't very well
submit a twenty-three line perl solution and what amounts to find+awk
one liner and leave it at that.  Newbies out there might get the wrong
idea and start writing shell scripts instead of perl scripts!

So here's another shell script which is very similar to fsizes.sh, but
uses a perl one-liner to do the job of both find and awk in that other
script.

--- fsizes2.sh ---
#!/bin/sh

if [ -z "$1" ]; then
    echo "usage $0 root-dir"
    exit 1
fi

perl -MFile::Find -e 'find sub {$s += -s if -f && !-l}, @ARGV; print "$s\n"' $1
--- end fsizes2.sh ---

And here's the equivalent code in pure perl...

--- fsizes2.pl ---
#!/usr/bin/perl -w

use File::Find;

die "Usage $0 root-dir\n" unless defined $ARGV[0];

find sub { $s += -s if (-f && !-l)}, $ARGV[0];
print "$s\n";
--- end fsizes2.pl ---

I'd be curious to see what a Python solution looks like.