Calculating relative average subdirectory filesizes

Published: Aug 21, 2020
Reading time: 1 min
Tags: Guides Linux Media Snippets Software 

During these unprecedented times I’ve been watching a fair amount of movies and TV shows, and deleting once done, as you do. As a bit of a interesting insight and guiding hand I’ve been using the excellent ncdu and rclone’s …clone which both work excellently for when 1 folder equates to 1 media. With TV shows however this is complicated somewhat. In steps calculating average filesizes in a directory so you can sort them revealing the most notorious offenders.

I had a quick look online but couldn’t find anything that really did what I wanted so I wrote it myself in an extremely verbose fashion. Eventually I slimmed it down to the following function:

for i in *; do s=$(du -s "$i" | awk '{print $1}') && c=$(find "$i" -type f -size +1M | wc -l) && echo "$((s / c)) $c $s $i"; done | sort -nr

What this does is:

Giving you your results. Ta~da!