du -dirs

Top Page
Attachments:
Message as email
+ (text/plain)
Delete this message
Reply to this message
Author: Kevin Buettner
Date:  
Subject: du -dirs
On Jun 23, 5:57pm, Eric Thelin wrote:

> Ah, but the shell script will count the files in the whole tree from the
> starting directory down. But the perl version will only count files in
> the directory itself. So for most uses the shell script is better. So
> newbies would be better off using the shell script. Of course this
> leaves a challenge for the perl hackers to fix\b\b\bimprove the perl
> version. OK, so I am writing this because I want the perl script to be
> as good as the shell one but I am too lazy to do it myself :)


Ummm... I think you'd better try it. Both scripts have identical
functionality.

I've tested it on my /usr/local hierarchy and got identical results:

ocotillo:ptests$ ./fsizes2.pl /usr/local
107029246
ocotillo:ptests$ ./fsizes2.sh /usr/local
107029246

> On Thu, 22 Jun 2000, Kevin Buettner wrote:
>
> > 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.
> >
> > _______________________________________________
> > Plug-discuss mailing list -
> > http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss
> >
>
> --
>
>
> _______________________________________________
> Plug-discuss mailing list -
> http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss
>-- End of excerpt from Eric Thelin