# Find the total size of certain files within a directory branch

Assume there is a photo storage space directory, claim, ./photos/john_doe, within which there are numerous subdirectories, where several particular files stay (claim, *.jpg). Just how can I compute a recap size of those files listed below the john_doe branch?

I attempted du -hs ./photos/john_doe/*/*.jpg, yet this reveals specific files just. Additionally, this tracks just the first nest degree of the john_doe directory, like john_doe/june/, yet misses john_doe/june/outrageous/.

So, just how could I go across the whole branch, summarizing the size of the particular files?

223
2022-06-07 17:04:40
Source Share
du -ch public_html/images/*.jpg | grep total
20M total


offers me the complete use of my .jpg files in this directory.

To manage numerous directory sites you 'd possibly need to incorporate this with find in some way.

You could find du command examples valuable (it additionally consists of find)

91
2022-06-07 18:06:28
Source
find ./photos/john_doe -type f -name '*.jpg' -exec du -ch {} + | grep total\$


If greater than one conjuration of du is called for due to the fact that the documents checklist is long, numerous total amounts will certainly be reported and also require to be summed.

285
2022-06-07 18:00:49
Source

Primarily, you require 2 points:

• the -c alternative to du, to inform it to generate a grand total amount ;
• either ** (activation instructions) or find (example) or to go across subdirectories
du -ch -- **/*.jpg | tail -n 1

44
2022-06-07 17:34:58
Source