Last active
November 26, 2022 16:11
-
-
Save grifferz/21cc591afe2e6994bc355c11824468fb to your computer and use it in GitHub Desktop.
Mastodon cache contents by file extension
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
#!/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