Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

My file system is set up like:

/ftp/data/ProductGroup*/ProductType*/Year*/Day*/ActualProductFile*

("*"denotes directory names that change)

I'd like to find out how much space is being used for 2011 products. Something like

du -ks /ftp/data/*/*/2011

However, I need the sum of all these directories - there are hundreds of them and I don't want to have to add them all up (too error prone!)

Would anyone have a suggestion?

share|improve this question
1  
and du's -c option isn't what you are looking for? –  llua Dec 27 '12 at 18:15
2  
@llua, not all du implementations support the -c option as that's not a standard option. –  Stéphane Chazelas Dec 27 '12 at 18:33
    
Ah, never knew that^ –  llua Dec 27 '12 at 19:48

1 Answer 1

Simply pipe the results from du into something that will perform the addition for you:

du -ks /ftp/data/*/*/2011 |
    sed -e 's/\(^[0-9]*\).*$/\1 +/' -e '1s/^/0 /' -e '$s/$/ p/' | dc
share|improve this answer
2  
I think using awk to sum the column would be more elegant some thing like du -ks /ftp/data/*/*/211 | awk '{ n+=$1; }; END { print n; }' –  donothingsuccessfully Dec 27 '12 at 18:32
    
Sure, that looks less cryptic than mine :-) –  Celada Dec 27 '12 at 19:18
    
Thank you to both! –  suri Dec 28 '12 at 17:24

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.