Operating System - HP-UX
1849065 Members
6370 Online
104041 Solutions
New Discussion

find total space used by files older than 9 years

 
SOLVED
Go to solution
Kirk MacLean_2
Frequent Advisor

find total space used by files older than 9 years

Hello fellow system guys and gals,

Is there a command that will give the total in KB or MB of all the files passed with a find command? I thought there was an option to do this with a "du" like utility:

find /archive -type f -mtime +3287 -exec du -sk {} \;

This is wrong because it evaluates each solution instead of writing the grand total.

Greatly appreciate your response,

Kirk
2 REPLIES 2
Sandman!
Honored Contributor
Solution

Re: find total space used by files older than 9 years

pipe the output of find to awk and sum the field that contains the file size...

# find /archive -type f -mtime +3287 -exec ll {} \; | awk '{tot+=$5}END{print tot}'

Note: change the argument of the "-exec" option from "du -sk" to "ll"
James R. Ferguson
Acclaimed Contributor

Re: find total space used by files older than 9 years

Hi Kirk:

# find /archive -type f -mtime +3287 | xargs du -ks | perl -nalF -e 'END{print $sz};$sz+=$F[0]'

Regards!

...JRF...