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 Johan for A standard tool to convert a byte-count into human KiB MiB etc; like du, ls1

$
0
0

Short and sweet, shell only solution:

convertB_human() {
NUMBER=$1
for DESIG in Bytes KB MB GB TB PB
do
   [ $NUMBER -lt 1024 ] && break
   let NUMBER=$NUMBER/1024
done
printf "%d %s\n" $NUMBER $DESIG
}

It doesn't show the decimal potion.

The let VAR=expression is Korn-ish. Substitute with VAR=$(( expression )) for Born-again-ish.


Viewing all articles
Browse latest Browse all 21

Trending Articles



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