From: tester on
Hi Gurus,
I am trying to write a script which gives me a detail report of no of
files in each sub dir of main dir and total size of the main dir as
below:

Dir structure is in Year/Month/Day format as below:

200601/01
200601/02
...
200601/31

200602/01
200602/02
..
..
200602/28 and so on..
There are thousnads of dir (YearMonth) and files under sub-dir days.
I am looking for a report with # files under each subdir and sub-dir
size in excel/formatted report:

Report:
DIR # Files Size
200601/01 1000 20GB
200601/02 1200 18GB
.....


Any Help is greatly appreciated.

From: Kenan Kalajdzic on
tester <bshah(a)citadon.com> wrote:
> I am trying to write a script which gives me a detail report of no of
> files in each sub dir of main dir and total size of the main dir as
> below:
>
> Dir structure is in Year/Month/Day format as below:
>
> 200601/01
> 200601/02
> ...
> 200602/01
> 200602/02
> .
> .
> 200602/28 and so on..
> There are thousnads of dir (YearMonth) and files under sub-dir days.
> I am looking for a report with # files under each subdir and sub-dir
> size in excel/formatted report:
>
> Report:
> DIR # Files Size
> 200601/01 1000 20GB
> 200601/02 1200 18GB
> ....

Assuming all the YearMonth directories are contained within the current
directory, the following script will generate the report (with filesize
in bytes):

printf "DIR\t# Files\tSize (bytes)\n"
for DIR in */*
do
printf "$DIR\t`ls -A "$DIR" | wc -l`\t`cat "$DIR"/* | wc -c`\n"
done

--
Kenan Kalajdzic