Lesser known linux commands : units

December 25, 2009

units is a command which help us to convert between different units of measure like feet into meter etc.

Let us see few examples

ram@rhlaptop:~$ units

2411 units, 71 prefixes, 33 nonlinear units

You have: foot

You want: cm

* 30.48

/ 0.032808399

You have: acre

You want: meter^2

* 4046.8726

/ 0.00024710439

You have: tempF(100)

You want: tempC

37.777778

As you can see it is pretty useful. How to interpret the results?. The first line if has a * means it should be multiplied.

For example in foot to cm conversion, following formula helps

1 foot = 30.48 * 1cm.

The second line shows the reverse, i.e cm to foot conversion, here division should be applied. For example cm to foot

cm =foot / 0.032808399

You can even give exact value that you want to convert. Say 10feet

You have: 10feet
You want: cm
* 304.8
/ 0.0032808399

As for as non-linear units like Fahrenheit to Celsius, there is a function like syntax as you can see in the third example.

The information about units is usually at /usr/share/misc/units.dat. A look at this file is good as it throws lot of information – reminding me about clarke’s table in school/college days.