Click to See Complete Forum and Search --> : Command to calc directory size? Forgotten


Spacecake
05-12-2002, 11:12 AM
Just a quicky. I have forgotten the command that will take a directory and all its subdirectories contents and add all the filesizes up for you. I think it's two letters long, i can't remember. Anyone know? Right now i'm just doing this:

CNT=0; for FILE in $(ls $1); do CNT=$[ $CNT + 1 ]; done
SIZE=$(ls -l $1 | awk -v size=0,amt=$CNT '{ size+=$5 ; if(NR==amt) { print size } }')
echo $SIZE

Blah!

slapNUT
05-12-2002, 03:51 PM
du -s /<directory>

Alex Cavnar, aka alc6379
05-13-2002, 10:58 PM
Originally posted by slapNUT:
<STRONG>du -s /&lt;directory&gt;</STRONG>

If you also add the -h option, it tells it in MB, kb or bytes, which ever is more "human readable"

mdwatts
05-14-2002, 06:01 AM
Of course the manpages for du and df are very helpful for finding out what options you can use with the command.

man du

man df