Last active
November 26, 2022 16:17
-
-
Save grifferz/58cf3b842540a4ea8fd5af453d080108 to your computer and use it in GitHub Desktop.
Mastodon cache files by byte count and 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_bytes.sh /path/to/mastodon/system/cache | |
cache_dir=${1-/opt/mastodon/web/system/cache} | |
# This will handle spaces in filenames, but not newlines in filenames… | |
find "$cache_dir" -type f -printf "%s %p\n" \ | |
| awk '{ | |
f_bytes=$1; $1 = "" # Nuke byte count | |
f_path=$0 # Everything else, so paths with spaces are included | |
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" } | |
byte_count[f_ext]+=f_bytes | |
total_bytes+=f_bytes | |
} | |
END { | |
for (key in byte_count) { | |
printf "%-7s %12lu %14s\n", | |
key, byte_count[key], | |
"(" sprintf("%.1f", byte_count[key] / 1024 / 1024) "MiB)" \ | |
| "sort -k 2 -rn" | |
} | |
close("sort -k 2 -rn") | |
print "-----" | |
printf "Total: %13lu %14s\n", | |
total_bytes, "(" sprintf("%.1f", total_bytes / 1024 / 1024) "MiB)" | |
}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment