5

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.

7
  • 6
    If not, that's an awesome idea for a utility. Commented Sep 11, 2014 at 14:53
  • 1
    linuxquestions.org/questions/programming-9/… Commented Sep 11, 2014 at 14:55
  • 1
    @Donal, link solves formatting problem, which is an opposite of arithmetical. Commented Sep 11, 2014 at 15:00
  • 4
    Try GNU units Commented Sep 11, 2014 at 15:00
  • 3
    I'm fine with the OP undeleting his post. I think adding an example to the answer would improve it. I only posted as a comment because I wasn't sure units actually allowed you to do calculations, and I couldn't be bothered to install it to test. ( Commented Sep 12, 2014 at 12:03

1 Answer 1

6

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.