Since no specific shell was mentioned, here's how to do the whole thing in the
ls -lhf **/*(.Lk-1024oL)
** glob pattern matches like
* but across
/ in pathnames, i.e. like a recursive search would do.
ls command would enable human readable sizes with
-h, and long list output format with
-f option disables sorting, so
ls would just list the files in the order they are given.
This order is arranged by the
**/*(.Lk-1024oL) filename globbing pattern so that the smaller files are listed first. The
**/* bit matches every file and directory in this directory and below, but the
(...) modifies the glob's behaviour (it's a "glob qualifier").
oL at the end that orders (
o) the names by file size (
. at the start makes the glob only match regular files (no directories).
Lk-1024 bit selects files whose size is less than 1024 KB ("length in KB less than 1024").
zsh is not your primary interactive shell, then you could use
zsh -c 'ls -lf **/*(.Lk-1024oL)'
setopt GLOB_DOTS (or
zsh -o GLOB_DOTS -c ...)
to also match hidden names. ... or just add
D to the glob qualifier string.
Expanding on the above, assuming that you'd want a 2-column output with pathnames and human readable sizes, and also assuming that you have
numfmt from GNU coreutils,
zmodload -F zsh/stat b:zstat
for pathname in **/*(.Lk-1024oL); do
printf '%s\t%s\n' "$pathname" "$(zstat +size "$pathname" | numfmt --to=iec)"
paste <( printf '%s\n' **/*(.Lk-1024oL) ) \
<( zstat -N +size **/*(.Lk-1024oL) | numfmt --to=iec )