du a directory

Howdy,
Quick question. I want to get a summary of the total size one file type is taking up in a directory. For example, I want to know how much space *.jpg are utilizing under the pix directory. I've tried "du -ks *.jpg" but this only displays the size of each individual jpg file, not the sum of all the jpgs. Any help would be great!

Thanks,
Ash

:rolleyes:

try the following:
here are my *.doc files:
$ du -ks *.doc
8 HP-Sequentcabinet.doc
8 OMNI.doc
8 bannerCMD.doc
8 diag.doc
16 expoLINUX.doc
8 hpOMNIjan.doc
8 hpTICKET3201114488.doc
8 interactive.doc
24 juliet_errors.doc
8 juliet_plex.doc
24 kateDISKerror-092202.doc
8 kernelSUNDAY.doc
8 keynote.doc
8 laninfo.doc
8 majorNUM.doc
8 myPRINTERS.doc
16 nettl1.doc
8 nettl2.doc
8 noEXPIREusers.doc
8 omniINFO.doc
8 omnibackFINALreorg.doc
16 omniinfo.doc
8 plenary.doc
8 q4notes.doc
8 ram.doc
8 shell.doc
8 special.doc
8 startup.doc
8 term.doc

here is a script you need to copy:
$ cat total.sh
#!/bin/sh
File=$1
let y=0
for x in `du -ks *."$File" | awk '{print $1}'`
do
let y=`expr $y+$x`
echo $y
done | echo "total $File files are ` tail -1 `KB "
exit

and here it is in action:
$ ./total.sh doc
total doc files are 288KB

enjoy,
manny

A quick single liner with awk that would work would be

du -ks *.jpg | awk '{ x+=$1 }; END { print "total " x "KB" }'

Thanks a ton, those both worked like a champ.

:smiley: