How can I know the total size taken by specific kind of files in my hard drive?

find ./path/to/your/drive -type f -name '*.jpg' -exec du -ch {} +

Or much faster

find /path/to/your/drive -name "*.jpg" -print0 | du -ch --files0-from=-

Or simply,

du -ch /path/to/your/drive/*.jpg | grep total

Or with help of awk,

find /path/to/your/drive -iname "*.jpg" -ls | awk '{total += $7} END {print total}'

On my system file size shows on seventh field, if it's different for you then adjust accordingly.

As requested by OP in comment, if you want to find all images from a directory and total size you can use this command (suggested by @Stéphane Chazelas)

 find . -type f -exec file --mime-type {} + | sed -n 's|: image/[^[:blank:]]*$||p' | tr '\n' '\0' | du --files0-from=- -hc

Or

 du -shc $(find . -name '*' -exec file {} \; | grep -o -P '^.+: \w+ image' | cut -d':' -f1) | grep total

As an alternative, you can do this using only POSIX:

find . -type f -name "*.jpg" -exec du -sk {} \; |
  awk 'BEGIN{total=0};{total += $1}; END{printf "%.3f MB\n", total / 1024}'

Further reading:

  • du - estimate file space usage (POSIX)
  • find - find files (POSIX)