-
-
Save arbal/211919f6be26c69926ca0a105821f8b0 to your computer and use it in GitHub Desktop.
Lists disk usage of files in the current folder by file extension
This file contains 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
# Based on answer from Yuval here: https://askubuntu.com/a/1214458/687179 | |
# output pairs in the format: `filename size`. | |
# I used `nawk` because it's faster. | |
find . -type f -print0 | xargs -0 stat -f'%N %z' | awk ' | |
{ | |
split($1, a, "."); # first token is filename | |
ext = a[length(a)]; # only take the extension part of the filename | |
size = $2; # second token is file size | |
total_size[ext] += size; # sum file sizes by extension | |
} | |
END { | |
# print sums | |
for (ext in total_size) { | |
print ext, total_size[ext]; | |
} | |
}' | sort -rn -k2,2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment