#!/bin/sh
# directory-sizes PATH LIMIT: the largest entries directly under PATH, in
# bytes, staying on its filesystem. Read-only; run by the host connector
# through sudo, so it trusts none of its arguments.
set -eu
[ "$#" -eq 2 ] || { echo "usage: directory-sizes PATH LIMIT" >&2; exit 2; }
case "$1" in /*) ;; *) echo "path must be absolute" >&2; exit 2 ;; esac
case "$2" in '' | *[!0-9]*) echo "limit must be a number" >&2; exit 2 ;; esac
LC_ALL=C du -x -B1 --max-depth=1 -- "$1" 2>/dev/null | sort -rn | head -n "$2"
