Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a command line calculator for byte calculations?

Tags:

linux

Is there a command line calculator for linux where I can do the following;

 calc 560kB/12233kB

for example. Basic arithmetic desired and answers given as a decimal (in the case above) or with the appropriate SI prefix (kB, B, MB, GB, etc.).

Could bc do the trick somehow?


Solution

GNU Units does what I wanted to.

like image 259
p014k Avatar asked Sep 30 '22 21:09

p014k


1 Answers

You can abuse bc for this if you remember that number unit actually is a shorthand for number * unit. One limitation of bc is that it only allows lower-case variables:

b=1
kb=1024
mb=1024*kb
...

scale=20
(560*kb)/(12233*kb)
.04577781410937627728

The next thing that I could think of is Python together with the units package.

like image 72
Aaron Digulla Avatar answered Oct 03 '22 02:10

Aaron Digulla