[comp.unix.ultrix] Re^2: Can ls show total Kbytes of "foo*"?

madd@world.std.com (jim frost) (10/29/89)

envbvs@epb2.lbl.gov (Brian V. Smith) writes:
>In article <1989Oct27.130914.12943@world.std.com>, madd@world.std.com
>(jim frost) writes:
>< You could just do "wc -c foo* | tail -1".

>Try that on some LARGE files and you will quickly (slowly) see that
>"wc" is much slower than the "ls."

Ok, the following alias ought to work:

alias tsize "(cd $HOME ; echo '#include <sys/stat.h>\
main(argc,argv) int argc;char **argv;{int t=0;struct stat s;\
while(--argc){stat(*(++argv),&s);t+=s.st_size;}\
printf("%d",t);}' >foo.c ; cc -o foo foo.c) ; $HOME/foo"

A bit slow for those small jobs but if you're talking Gb files it'll
work great :-).

jim frost
software tool & die     "The World" Public Access Unix for the '90s
madd@std.com            +1 617-739-WRLD  24hrs {3,12,24}00bps

dhesi@sunscreen.UUCP (Rahul Dhesi) (10/30/89)

I use shell scripts called "bytes" and "blocks".  They are:

bytes:
   /bin/ls -l $* | awk '{sum = sum + $4} END {print sum}'

blocks:
   du -s $* | awk '{total += $1} END {print total}'

(System V users may need to adjust the field number in the first one.)

The "blocks" script gives me total blocks used by specified files and
directory subtrees.

Rahul Dhesi <dhesi%cirrusl@oliveb.ATC.olivetti.com>
UUCP:  oliveb!cirrusl!dhesi
Use above addresses--email sent here via Sun.com will probably bounce.