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

Answer by Bence Kiglics for A standard tool to convert a byte-count into...

I had the same problem and I quickly came up with a simple solution using awk's log() function: awk ' BEGIN { split("B,kiB,MiB,GiB", suff, ",") } { size=$1; rank=int(log(size)/log(1024)); printf...

View Article



Answer by ThorSummoner for A standard tool to convert a byte-count into human...

Python tools exist $pip install humanfriendly # Also available as a --user install in ~/.local/bin $humanfriendly --format-size=2048 2.05 KB $humanfriendly --format-number=2048 2,048 I don't see a...

View Article

Answer by Camilo Martin for A standard tool to convert a byte-count into...

Here's a bash-only option, no bc or any other non-builtins, + decimal format and binary units. bytesToHuman() { b=${1:-0}; d=''; s=0; S=(Bytes {K,M,G,T,P,E,Z,Y}iB) while ((b > 1024)); do d="$(printf...

View Article

Answer by craeckie for A standard tool to convert a byte-count into human KiB...

@don_crissti's first Answer is good, but can be even shorter using Here Strings, e.g. $ numfmt --to=iec-i <<< "12345" 13Ki $ numfmt --to=iec-i --suffix=B <<< "1234567" 1.2MiB or even...

View Article

Answer by Geoffrey for A standard tool to convert a byte-count into human KiB...

Here is a way to do it almost purely in bash, just needs 'bc' for the floating point math. function bytesToHR() { local SIZE=$1 local UNITS="B KiB MiB GiB TiB PiB" for F in $UNITS; do local UNIT=$F...

View Article


Answer by Chris for A standard tool to convert a byte-count into human KiB...

user@host:/usr$ alias duh="du -s -B1 * | sort -g | numfmt --to=iec-i --format='%10f'" user@host:/usr$ duh Gives: 4.0Ki games 3.9Mi local 18Mi include 20Mi sbin 145Mi bin 215Mi share 325Mi src 538Mi lib...

View Article

Answer by FJL for A standard tool to convert a byte-count into human KiB MiB...

Actually, there is a utility that does exactly this. I know cos it was me wot wrote it. It was written for *BSD but ought to compile on Linux if you have the BSD libraries (which I believe are common)....

View Article

Answer by mikeserv for A standard tool to convert a byte-count into human KiB...

The answer to your question is yes. While the output format isn't exactly to your specification, the conversion itself is easily done by a very standard tool (or two). The ones to which I refer are dc...

View Article


Answer by sdaau for A standard tool to convert a byte-count into human KiB...

Via linux - Is there a command line calculator for byte calculations? - Stack Overflow, I found about GNU Units - though without examples on the SO page; and as I didn't see it listed here, here is a...

View Article


Answer by Johan for A standard tool to convert a byte-count into human KiB...

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...

View Article

Answer by John for A standard tool to convert a byte-count into human KiB MiB...

This is a complete rewrite inspired by Peter.O's modified version of Gilles' awk script. Changes: Fixes Peter.O's bug where he looks for a string of >1 character where he should be looking for one...

View Article

Answer by don_crissti for A standard tool to convert a byte-count into human...

As of v. 8.21, coreutils includes numfmt: numfmt reads numbers in various representations and reformats them as requested. The most common usage is converting numbers to / from human representation....

View Article

Answer by Stéphane Chazelas for A standard tool to convert a byte-count into...

There are a couple of perl modules on CPAN: Format::Human::Bytes and Number::Bytes::Human, the latter one being a bit more complete: $ echo 100 1000 100000 100000000 | perl -M'Number::Bytes::Human...

View Article


Answer by Gilles 'SO- stop being evil' for A standard tool to convert a...

No, there is no such standard tool. Since GNU coreutils 8.21 (Feb 2013, so not yet present in all distributions), on non-embedded Linux and Cygwin, you can use numfmt. It doesn't produce exactly the...

View Article

Answer by darnir for A standard tool to convert a byte-count into human KiB...

AFAIK there is no such standard tool to which you can pass text and it returns a human readable form. You may be able to find a package to accomplish the said task for your distro. However, I do not...

View Article


A standard tool to convert a byte-count into human KiB MiB etc; like du, ls1

Is there a standard tool which converts an integer count of Bytes into a human-readable count of the largest possible unit-size, while keeping the numeric value between 1.00 and 1023.99 ? I have my...

View Article

Answer by Bryan Roach for A standard tool to convert a byte-count into human...

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;...

View Article


Answer by Most Wanted for A standard tool to convert a byte-count into human...

pip install humanfriendly and then add a simple function to your default shell (e.g. ~/.bashrc)function fsize() { humanfriendly --format-size `stat -f '%z' $1` } Use like this➜ fsize file.txt 6.17 KB

View Article

Answer by igonejack for A standard tool to convert a byte-count into human...

https://github.com/gonejack/hsize:go get -u github.com/gonejack/hsize> echo 31415 | hsize31415 => 30.68KB> hsize 46783 9292921146783 => 45.69KB92929211 => 88.62MB

View Article

Answer by Oliver for A standard tool to convert a byte-count into human KiB...

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 / |...

View Article

Answer by mgutt for A standard tool to convert a byte-count into human KiB...

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),...

View Article

Browsing latest articles
Browse All 21 View Live




Latest Images