#!/bin/sh
# old-files PATH MINUTES LIMIT: the largest files under PATH not modified for
# MINUTES, staying on its filesystem, as size, mtime, owner and path.
# Read-only; run by the host connector through sudo, so it trusts none of its
# arguments.
set -eu
[ "$#" -eq 3 ] || { echo "usage: old-files PATH MINUTES LIMIT" >&2; exit 2; }
case "$1" in /*) ;; *) echo "path must be absolute" >&2; exit 2 ;; esac
case "$2" in '' | *[!0-9]*) echo "minutes must be a number" >&2; exit 2 ;; esac
case "$3" in '' | *[!0-9]*) echo "limit must be a number" >&2; exit 2 ;; esac
LC_ALL=C find "$1" -xdev -type f -mmin +"$2" -printf '%s\t%T@\t%u\t%p\n' 2>/dev/null | sort -rn | head -n "$3"
