Skip to content

Instantly share code, notes, and snippets.

@grifferz
Last active November 26, 2022 16:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grifferz/21cc591afe2e6994bc355c11824468fb to your computer and use it in GitHub Desktop.
Save grifferz/21cc591afe2e6994bc355c11824468fb to your computer and use it in GitHub Desktop.
Mastodon cache contents by file extension
#!/bin/sh
# Probably needs GNU AWK. Come to think of it, some OSes
# won't have a `find` with -printf like GNU does.
# Usage:
# ./cache_by_ext.sh /path/to/mastodon/system/cache
cache_dir=${1-/opt/mastodon/web/system/cache}
find "$cache_dir" -type f -printf "%p\n" \
| awk '{
f_path=$0
ext_pos=match($f_path, /\.[^\.]+$/)
f_ext=substr($f_path, ext_pos+1) # +1 to skip over . itself
# Consider .jpeg to be .jpg.
if (f_ext == "jpeg") { f_ext="jpg" }
ext_count[f_ext]++
file_count++
}
END {
for (key in ext_count) {
printf "%-7s %8lu\n",
key, ext_count[key] \
| "sort -k 2 -rn"
}
close("sort -k 2 -rn")
print "-----"
printf "Total: %9lu files\n", file_count
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment