du -dirs

Kevin Buettner kev@primenet.com
Thu, 22 Jun 2000 01:29:45 -0700


Below another way to do it that doesn't use perl.  But, even though
this solution appears to be shorter, it took me about five times as
long to come up with it.  (I was trying to do a wc -c `find ...` for a
while.  The problem with that is that there's a limit to the length of
a command.  You can use xargs to avoid this limitation, but that'll
potentially run several wc commands, which is not what you want.)

I also tried constructing a really long expression 34343+234324+...+234324
and feeding it to bc, but unfortunately bc appears to (ahem) have line
length limitations.  (Some enterprising person might take a look at this
problem, fix it, and submit a patch to the appropriate maintainers.)

--- fsizes.sh ---
#!/bin/sh

find $1 -type f -not -type l -printf '%s\n' | awk -- '{s += $0} END {print s}'
--- end fsizes.sh ---

Here's how to use it:

ocotillo:ptests$ ./fsizes.sh /usr/local
110960876