Skip to content

Instantly share code, notes, and snippets.

@dannyNK
Created April 15, 2021 08:31
Show Gist options
  • Save dannyNK/41f08ee7717d1b545a63c80ad61708a2 to your computer and use it in GitHub Desktop.
Save dannyNK/41f08ee7717d1b545a63c80ad61708a2 to your computer and use it in GitHub Desktop.
Lists disk usage of files in the current folder by file extension
# 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