When you just want a quick conversion without fancy output, or when the numfmt is not available, I find the units
handy. Eg define the following in your .bashrc:
convu() { conv=$( units $2 $3 | grep / | cut -f 2 -d " " ) echo $(( $1 / $conv ))}
Then you can do this:
$ convu 268435456 bytes megabytes256
or this:
$ convu $( some command that outputs a value in bytes ) bytes megabytes256
Additionally if you define unit abbreviations in a file, say ~/.units.bytes
then you can define convu
instead as
convu() { conv=$( units -f ~/.units.bytes $2 $3 | grep / | cut -f 2 -d " " ) echo $(( $1 / $conv ))}
If the file has
bit !h!nibble 4 bitnybble nibblebyte 8 bitword 2 byteblock 512 bytekbyte 1024 bytemegabyte 1024 kbytegigabyte 1024 megabyteterabyte 1024 gigabytepetabyte 1024 terabyteexabyte 1024 petabytezettabyte 1024 exabyteyottabyte 1024 zettabytekilobyte kbytemeg megabytebaud bit/secb bytemb megabytegb gigabytekb kilobyte
then you can write
$ convu 268435456 b mb256