Skip to content

Instantly share code, notes, and snippets.

@kkew3
Forked from fsteffenhagen/sum_filesize.sh
Last active February 17, 2023 17:27
Show Gist options
  • Save kkew3/46b32c1d7fcd601ff67ff68a00eb3e99 to your computer and use it in GitHub Desktop.
Save kkew3/46b32c1d7fcd601ff67ff68a00eb3e99 to your computer and use it in GitHub Desktop.
sum human readable file sizes from `du` with `numfmt` and `perl`
# Require: [`fd`](https://github.com/sharkdp/fd.git)
PATTERN='XXX' # Assume this would be a directory
fd -0 -td "$PATTERN" \
| xargs -0 du -sh \
| numfmt --from=auto --to=none \
| perl -ane 'BEGIN { my $sum = 0; } $sum += $F[0]; print; END { print $sum, " totoal\n"; }' \
| numfmt --from=none --to=si
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment