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

$
0
0

This is what I'm using:

echo 10000000 | awk '{split("Byt,KiB,MiB,GiB,TiB", unit, ","); (size=$1) ? level=sprintf("%.0d", (log(size)/log(1024))) : level=0; printf "%.2f %s\n", size/(1024**level), unit[level+1]}'

returns 9.54 MiB

Example with path:

stat --format "%s %n" /boot/* | awk '{split("Byt,KiB,MiB,GiB,TiB", unit, ","); (size=$1) ? level=sprintf("%.0d", (log(size)/log(1024))) : level=0; printf "%8.2f %s ", size/(1024**level), unit[level+1]; print $2}'

returns:

   32.00 KiB /boot/EFI   32.00 KiB /boot/System   19.78 MiB /boot/bzfirmware   65.00 Byt /boot/bzfirmware.sha256    4.60 MiB /boot/bzimage   65.00 Byt /boot/bzimage.sha256   11.98 MiB /boot/bzmodules   65.00 Byt /boot/bzmodules.sha256  141.09 MiB /boot/bzroot   69.33 MiB /boot/bzroot-gui   65.00 Byt /boot/bzroot-gui.sha256   65.00 Byt /boot/bzroot.sha256   18.82 KiB /boot/changes.txt   32.00 KiB /boot/config  119.44 KiB /boot/ldlinux.c32   68.00 KiB /boot/ldlinux.sys    7.79 KiB /boot/license.txt   32.00 KiB /boot/logs    1.72 KiB /boot/make_bootable.bat    3.21 KiB /boot/make_bootable_linux    2.37 KiB /boot/make_bootable_mac  146.51 KiB /boot/memtest   32.00 KiB /boot/previous   32.00 KiB /boot/syslinux

Viewing all articles
Browse latest Browse all 21

Trending Articles



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