#bzip3 continues to amaze me:

-rw-r--r-- 1 ~~~ ~~~ 100M Apr 1 2025 outbox.json $ simplify $(bzip3 < outbox.json |wc -c) 4.57 MiB $ simplify $(xz -9e < outbox.json |wc -c) 4.69 MiB $ simplify $(zstd --ultra -22 < outbox.json |wc -c) 5.06 MiB

(I didn't time it, but it was much faster than the other two)

Also, just in case anyone's curious, simplify (poor name pick, but I couldn't think of anything better) is just a bash function for converting byte counts to an SI unit:

function simplify { #Reduces a big bytes count down to megabytes or whatnot local steps num [ $1 ] || ( warn "simplify() called without parameters\n (requires a number of bytes with no unit name)"; return 1 ) steps=0 num=$1 while [[ $(echo "$num > 1024" |bc) == 1 ]] #bc has to be used because num is a float do let steps++ num=$(echo "$num/1024" |bc -l) done #Cut off after two decimal place: num=$(echo "$num" |sed 's/\(\.[0-9][0-9]\)[0-9]*$/\1/') printf "$num " case $steps in 0) echo b;; 1) echo KiB;; 2) echo MiB;; 3) echo GiB;; 4) echo TiB;; 5) echo PiB;; 6) echo EiB;; 7) echo ZiB;; 8) echo YiB;; *) echo "1024 ^ $steps bytes";; esac }

@rl_dane

gestures towards numfmt --to=iec-i --suffix B $num

@algernon

Oof. Well, at least my function gives decimal results. XD
(And doesn't require GNU coreutils)

But yeah, if I had known about that, I wouldn't have written the shell function. XD

@rl_dane numft can round, you can use a format string, set the precision, etc. The possibilities are endless!

I learned about it about a month or so ago, when I shared a very similar shell function as yours. Someone pointed me to numfmt, now I'm paying the favour forward :D

@rl_dane Should be "B" instead of "b" for bytes. :P