Skip to content

Instantly share code, notes, and snippets.

@alexey-m-ukolov
Last active October 29, 2015 04:24
Show Gist options
  • Save alexey-m-ukolov/a44187bc7ff842b16894 to your computer and use it in GitHub Desktop.
Save alexey-m-ukolov/a44187bc7ff842b16894 to your computer and use it in GitHub Desktop.
Calculating total file size by extension in a directory
# SOURCE:
http://serverfault.com/questions/367185/calculating-total-file-size-by-extension-in-shell
# Specific extension:
find . -name '*.YOUR_EXTENSION' -exec ls -l {} \; | awk '{ Total += $5} END { print Total }'
# All extensions:
#!/bin/bash
ftypes=$(find . -type f | grep -E ".*\.[a-zA-Z0-9]*$" | sed -e 's/.*\(\.[a-zA-Z0-9]*\)$/\1/' | sort | uniq)
for ft in $ftypes
do
echo -n "$ft "
find . -name "*${ft}" -exec ls -l {} \; | awk '{total += $5} END {print total}'
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment