File: //usr/local/bin/top10.sh
#!/usr/bin/env bash
# top10bigfiles.sh
# Usage: ./top10bigfiles.sh [PATH]
# Prints the ten largest files beneath PATH (default: current dir),
# human‑readable, sorted biggest → smallest.
TARGET="${1:-.}"
if command -v numfmt >/dev/null 2>&1; then
# GNU coreutils present: easy byte→IEC conversion
find "$TARGET" -type f -printf '%s\t%p\n' 2>/dev/null \
| sort -nr \
| head -n 10 \
| numfmt --to=iec --field=1 --padding=7 \
| column -t
else
# Fallback without numfmt
find "$TARGET" -type f -printf '%s\t%p\n' 2>/dev/null \
| sort -nr \
| head -n 10 \
| awk '{
split("B KB MB GB TB PB",u);
s=$1; i=1;
while (s>=1024 && i<6) {s/=1024; i++}
size=sprintf("%.1f %s",s,u[i]);
sub($1 FS,""); # remove size from $0, leave full path (handles spaces)
printf "%-8s %s\n", size, $0;
}' \
| column -t
fi