Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

My file system is set up like:


("*"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
and du's -c option isn't what you are looking for? – llua Dec 27 '12 at 18:15
@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

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
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


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.