Quantcast
Channel: A standard tool to convert a byte-count into human KiB MiB etc; like du, ls1 - Unix & Linux Stack Exchange
Viewing all articles
Browse latest Browse all 21

Answer by Bryan Roach for A standard tool to convert a byte-count into human KiB MiB etc; like du, ls1

$
0
0

If you can use Python and pip, you can solve this with humanize. (Thanks to Pyrocater for the idea.)

$ pip install humanize
$ bytes=35672345337
$ python -c "import humanize; print(humanize.naturalsize($bytes))"

35.7 GB

$ seq 0 750000 2250000 |python -c $'import sys, humanize\nfor n in sys.stdin: print(humanize.naturalsize(n))'

0 Bytes
750.0 kB
1.5 MB
2.2 MB

Viewing all articles
Browse latest Browse all 21

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>