Sum of file size in directory / subdirectory

Hi ,

I am trying to write something to find the size of particular type of files in a directory & it's subdirectory and sum the size .. These types of file are found at directory level or its subdirectories level ..

#!/bin/ksh
FNAME='.pdf'
S_PATH=/abc/def/xyz
find $S_PATH   -exec ls -lad {} \; 	> temp1
cat temp1 | grep -i $FNAME	             > temp2 
awk 'NR>5{+$5}END{ print "Total " i}' temp2

Seems my awk is not working.. I am doing something stupid with awk.. Any simple way would be appreciated.
Input is

-rw-r--r--    1 owner abcdef        1031 Sep 07 12:57 /abc/def/xyz/PAY_WFM/unique.pdf
-rw-r--r--    1 owner abcdef        6279 Sep 07 12:57 /abc/def/xyz/SA1/unique.pdf
-rw-r--r--    1 owner abcdef         987 Sep 07 11:59 /abc/def/xyz/T1/unique.pdf
-rw-r--r--    1 owner abcdef        1650 Sep 07 12:57 /abc/def/xyz/A1/unique.pdf
-rw-r--r--    1 owner abcdef       83477 Sep 07 12:57 /abc/def/xyz/DM/unique.pdf
-rw-r--r--    1 owner abcdef        5845 Sep 07 12:57 /abc/def/xyz/TH/unique.pdf
-rw-r--r--    1 owner abcdef        3266 Sep 07 12:57 /abc/def/xyz/MR/unique.pdf
-rw-r--r--    1 owner abcdef       37295 Sep 07 12:57 /abc/def/xyz/PPO/unique.pdf
-rw-r--r--    1 owner abcdef      242529 Sep 07 12:57 /abc/def/xyz/P/unique.pdf
-rw-r--r--    1 owner abcdef       43072 Sep 07 12:57 /abc/def/xyz/P2/unique.pdf
-rw-r--r--    1 owner abcdef        5485 Sep 07 12:57 /abc/def/xyz/P/unique.pdf
-rw-r--r--    1 owner abcdef        4849 Sep 07 12:05 /abc/def/xyz/TP/skvunique.txt
-rw-r--r--    1 owner abcdef       58730 Sep 07 12:57 /abc/def/xyz/M1/unique.pdf

Output wanted is --- > 494495 (which is sum of values in 5th column)

Thanks in advance.
Vaddadi

Hi.

Why did you skip the first 5 rows?

$ awk '{T+=$5} END {print T}' inputfile
494495

Find also has an ls option, so no need for exec, really.

Your find also doesn't exclude directories (i.e. maybe you want -type f in there).

I was having some header line in the file so I wanted to skip them..

Anyway.. I removed the header and then your instruction worked like champ..

Can we merge find | cat | awk command in single line ..

Thanks .. Vaddadi

Hi.

I think you need at least two command.

You could use something like:

find $S_PATH -type f -name "*.pdf" -ls 2> /dev/null | awk '{T+=$7} END {print T}'

(the size is $7 for my find -ls)

Thanks it worked like a champ ..