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.

Assume there's an image storage directory, say, ./photos/john_doe, within which there are multiple subdirectories, where many certain files reside (say, *.jpg). How can I calculate a summary size of those files below the john_doe branch?

I tried du -hs ./photos/john_doe/*/*.jpg, but this shows individual files only. Also, this tracks only the first nest level of the john_doe directory, like john_doe/june/, but skips john_doe/june/outrageous/.

So, how could I traverse the entire branch, summing up the size of the certain files?

share|improve this question
add comment

3 Answers 3

up vote 6 down vote accepted
find ./photos/john_doe -type f -name '*.jpg' -exec du -ch {} +
share|improve this answer
    
Thank Gilles for shortening the answer –  SHW Jun 26 '12 at 6:34
add comment
du -ch public_html/images/*.jpg | grep total
20M total

gives me the total usage of my .jpg files in this directory.

To deal with multiple directories you'd probably have to combine this with find somehow.

You might find du command examples useful (it also includes find)

share|improve this answer
    
This doesn't traverse the underlying directories? –  mbaitoff Jun 26 '12 at 5:48
add comment

Primarily, you need two things:

  • the -c option to du, to tell it to produce a grand total;
  • either find or ** to traverse subdirectories.
du -ch **/*.jpg | tail -n 1
share|improve this answer
add comment

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.