Command line unit conversion

Spread the love

The Linux command ‘units’ may or may not be installed on your system. If not, if you use synaptic or apt, type (at the prompt)

sudo apt-get install units

or equiviliant for other distributions. Then type in the word “units” and play around. Here are a few sample outputs:

i-89547af38f3e53e357d45983aaf95b6c-units_eg.jpg

The program is a little clunky. You have to know the specific codes for each type of measurement, though ‘units’ will figure out what you mean sometimes. To exit, type ctrl-D. There is a way to use this utility in a script. That and other details are found in the manual.

Have you read the breakthrough novel of the year? When you are done with that, try:

In Search of Sungudogo by Greg Laden, now in Kindle or Paperback
*Please note:
Links to books and other items on this page and elsewhere on Greg Ladens' blog may send you to Amazon, where I am a registered affiliate. As an Amazon Associate I earn from qualifying purchases, which helps to fund this site.

Spread the love

11 thoughts on “Command line unit conversion

  1. Bill: Thanks. I was going to mention, but forgot, that you can get often better results, with more understanding of your particular vocab, from Google. Right after writing this post up I needed to convert grams to oz, and units would not do that because I did not know the term for oz as in weight as opposed to volume. Google understood my needs and met them.

    But, google is clumsy in a script, and if you do this a lot with certain conversions units is probably faster. Plus, as a GPL utility, it is verifiable. I’m not sure if Google’s conversion is, so it may not be suitable for science (good chance it’s the same utility with a front end, though.)

  2. Well, oz _is_ the unit of weight. The fluid ounce is abbreviated fl oz.

    If units is using oz for the fluid ounce and never as the ounce itself, then units is doing it wrong.

  3. Oh, and I was trying to convert ml to oz. But, it still doesn’t function as expected, i.e., “fluid ounce” is not recognized as a unit, nor is “fl oz” … after five or six unsuccessful guessies one reaches for Google. The units utility should know which ounce one is looking for if volume vs. weight is the first measurement. But, it is open source and thus fixable, unless there is some philosophical barrier here.

  4. Start with units -v (verbose, my preference), type fl and hit the tab key: flag flock flour_sifted fluiddram fluorine fldr florin flour_spooned fluidounce fluxunit flemishell flour_scooped floz fluidscruple

    fluidounce or floz will get you fluidounce = usfluidounce = 1|16 uspint = 2.957353e-05 m^3

  5. I’ve always been fond of ConvertAll. It’s usually run as a GUI, but it works just fine as a CLI app. I like it because you can make units out of other units easily. lb / acre == 1.1208512 kg / hectare, for example.

  6. I use Google Calc almost daily at work to work out bandwidth requirements for customers. From what you’ve shown above it looks like units syntax is far more forgiving than Google’s – which generally needs to be phrased as an algorithm of sorts. i.e. (10Mb*2592000)*.6=?TB

    answer is 1.85394287TB in each direction over a 10Mbps connection, over 30 days allowing for ~40% tcp/ip packet overhead.

  7. Glad to finally find an answer to the fluid ounce problem with the units application. I want to add this all-important shortcut:

    ctrl + t (opens terminal)

    units “100 ml” “floz”
    (returns 3.3814023 — maybe I’ll go with the 150 mL flask)

    I much prefer this quick keyboard action to Google for my conversions, and it’s no competition when my browser is not running.

Leave a Reply to Greg Laden Cancel reply

Your email address will not be published. Required fields are marked *