Newsgroups: comp.unix.questions
Path: utzoo!telly!robohack!druid!darcy
From: darcy@druid.uucp (D'Arcy J.M. Cain)
Subject: Re: What's wrong with this Bourne shell script?
Message-ID: <1990Aug8.194618.8742@druid.uucp>
Organization: D'Arcy Cain Consulting, West Hill, Ontario
References: <1990Aug3.193231.3166@silma.com> <834@hls0.hls.oz>
Date: Wed, 8 Aug 90 19:46:18 GMT

In article <834@hls0.hls.oz> george@hls0.hls.oz (George Turczynski) writes:
>In article <1990Aug3.193231.3166@silma.com>, aab@silma.com (Andy Burgess) writes:
>> While you're at it, is there a better way to get the total bytes
>> of the files in a directory?
>You could try something like this:
>ls -ld * | awk '{ sum+= $4 } END { print sum }'

Here is a script I use to check directory usage:

------------------------ Start of script ----------------------------
#!
# Checks the space used by a directory
# Written by D'Arcy J.M. Cain

# default to current directory else from command line
if [ "$1" = "" ]
then
	directory=`pwd`
else
	directory=$1
	shift
fi

while true
do
	if [ "$directory" = "" ]
	then
		exit 0
	fi

	echo "$directory \c"
	ls -iRl $directory | awk '{ if (NF > 5) print $0 }' | sort | awk '{
		if ($1 != last_inode) size = size + $6
		last_inode = $1
		}
		END { print size }'

	if [ "$1" = "" ]
	then
		exit 0
	fi

	shift
	directory=$1
done
---------------------- End of script ----------------------

The difference is that subdirectories are included and links are only
counted once.  Also there is a little user friendly wrapping.  HTH.

-- 
D'Arcy J.M. Cain (darcy@druid)     |
D'Arcy Cain Consulting             |   MS-DOS:  The Andrew Dice Clay
West Hill, Ontario, Canada         |   of operating systems.
+ 416 281 6094                     |
