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?
summed byte size
– Michal Čizmazia Jul 15 '15 at 13:55LC_ALL=POSIX
as prefix to always grep for total like this:LC_ALL=POSIX find ./photos/john_doe -type f -name '*.jpg' -exec du -ch {} + | grep total$
– Sven Jun 27 '16 at 05:48-name
, then change the grep togrep -P "\ttotal$"
or else it will capture all files ending with "total" as well. – thdoan Mar 30 '17 at 07:43bc
, so here is a more portable solution:find -name '*.jpg' -type f -exec du -bc {} + | grep total$ | cut -f1 | awk '{ total += $1 }; END { print total }'
– thdoan Mar 30 '17 at 07:55...|grep -v .jpg$
– iRaS Oct 13 '20 at 06:53+
do at the end of thefind
command? I couldn't find any mention of it inman find
. – localhost Jan 01 '21 at 14:31bc
does not operate well, it is better to use:find -iname 'file*' -exec du -cb {} + |grep -e "total$" |cut -f1 |paste -sd+ - |bc |numfmt --to=iec --suffix=B --round=towards-zero
– Jester May 17 '21 at 06:59bash
or Linux or GNUfind
. – Cliff Aug 31 '22 at 04:23