1

Is there a standard command that will format a simple value (size in bytes) as a human readable format (similar to the -h switch on du, ls, ...)?

eg.

echo 1852 | format       # should print 1.9K
echo 3145728000 | format # should print 3.0G
Inian
  • 12,807
laktak
  • 5,946
  • should that be in the short (k=1^3) or long (k=2^10) scale? –  Sep 15 '20 at 08:43
  • This is https://unix.stackexchange.com/q/44040/5132 again, similar to https://unix.stackexchange.com/q/346902/5132 . – JdeBP Sep 15 '20 at 10:12

1 Answers1

2

I think you are looking for the numfmt tool, which can covert raw strings to known math standards, e.g.

 echo 3145728000 | numfmt --to=iec
 3.0G

The tool is part of the GNU coreutils family.

Inian
  • 12,807