Last active
October 29, 2015 04:24
-
-
Save alexey-m-ukolov/a44187bc7ff842b16894 to your computer and use it in GitHub Desktop.
Calculating total file size by extension in a directory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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