208 lines
12 KiB
Plaintext
208 lines
12 KiB
Plaintext
|
|
Episode: 1213
|
||
|
|
Title: HPR1213: LiTS 026: units
|
||
|
|
Source: https://hub.hackerpublicradio.org/ccdn.php?filename=/eps/hpr1213/hpr1213.mp3
|
||
|
|
Transcribed: 2025-10-17 21:44:29
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
Welcome to Linux in the Shell Episode 26, the UNIS command.
|
||
|
|
My name is Dan Waschko, as always I am your host.
|
||
|
|
I'd like to thank Hacker Public Radio for hosting the website and the audio files and
|
||
|
|
being an all-around wonderful community.
|
||
|
|
So consider contributing to Hacker Public Radio or at the very least head on over there
|
||
|
|
to see the other exciting shows that are available at hackerpublicradio.org.
|
||
|
|
Last episode I talked about some mathematics in the command line and focused on the BC
|
||
|
|
command.
|
||
|
|
And I ended with talking about some unit conversions.
|
||
|
|
Well, this episode, I'm going to talk about a tool that makes it really easy to do unit
|
||
|
|
conversions without having to know the functions or equations behind converting between
|
||
|
|
units.
|
||
|
|
And that is the units command.
|
||
|
|
Take the BC command, if you execute the units, units, not units, units command, you end
|
||
|
|
up in an interactive shell.
|
||
|
|
So what you can do at this point is begin converting units.
|
||
|
|
Now I want to warn you about a couple of things.
|
||
|
|
First, chances are units is not installed by default.
|
||
|
|
Just head on over to your package manager, look for the command units, sort of software
|
||
|
|
units, UNITS, it's plural.
|
||
|
|
I found it in Arches in the main repository, is Pacman-CapitalS, units, install it right
|
||
|
|
away.
|
||
|
|
Secondly, units at first glance is really simple, but can get complex and frustrating
|
||
|
|
really fast.
|
||
|
|
Well, let's step back a second.
|
||
|
|
When you fire up the units command, you're going to be presented with an interactive
|
||
|
|
shell.
|
||
|
|
That shows you some information about units like BC did.
|
||
|
|
It shows you the, some of the conversions available to it, the metrics behind it, conversion
|
||
|
|
exchange rates from, and it gives you a date, mine says 2012, dash 10, dash 24, so that's
|
||
|
|
October 24, 2012.
|
||
|
|
It'll also tell you the number of unit conversions available, mine says 2500, 65 units, 85
|
||
|
|
prefixes, and 66 nonlinear units.
|
||
|
|
That's just some basic information, probably won't mean much to you, but that's just there
|
||
|
|
for your information.
|
||
|
|
Then you're presented with the first prompt, it says you have colon.
|
||
|
|
Now that's where you enter the units that you have, and for example, let's say 300 feet.
|
||
|
|
If we enter in 300 feet and hit the enter button, it's then going to present you with
|
||
|
|
the next prompt, it says you want.
|
||
|
|
Now you enter some unit that you want to convert 300 feet into, I'll say inches.
|
||
|
|
So when I hit 300 feet, converting to inches, I get the return value of 3600 or 3600 inches.
|
||
|
|
That's not all I get.
|
||
|
|
I get an asterisk that says 3600, and I get a, a next one, another one has a forward slash
|
||
|
|
that gives me another value.
|
||
|
|
Another value is 0.0002777777778.
|
||
|
|
What does that mean?
|
||
|
|
Well, the first value, obviously, is the conversion that I wanted, 3600 inches or 3600 inches.
|
||
|
|
The second value is the inversion of that conversion.
|
||
|
|
So that's basically red.
|
||
|
|
There are 0.0002777777778 inches in 300 feet.
|
||
|
|
It's just a conversion, quite simple.
|
||
|
|
Pretty elegant, pretty nifty to have if you wanted that information.
|
||
|
|
Maybe you didn't, but you got it anyway.
|
||
|
|
So you're saying to yourself right now, this is great.
|
||
|
|
I can be converting right and left between everything I want.
|
||
|
|
I don't have to fire up a calculator and start typing things in.
|
||
|
|
Remember some funky equation or a function to convert between the values that I want?
|
||
|
|
Well, yes and no.
|
||
|
|
It is great, but you have to understand that other caveat I said that it's sometimes
|
||
|
|
it's not as evident as you'd expect it to be.
|
||
|
|
Case in point, converting between temperature, Celsius and Fahrenheit.
|
||
|
|
You might think, oh, I'll just type in 10 degrees Celsius or 10 degrees, 100 degrees Celsius
|
||
|
|
and get the conversion to Fahrenheit.
|
||
|
|
No, it's not that simple because if you type in 100 degrees, you're not going to get
|
||
|
|
what you expect.
|
||
|
|
You're not going to find degrees.
|
||
|
|
Now, most versions of units will have been compiled with realign support and you will have
|
||
|
|
tab completion.
|
||
|
|
So you can type in 100 space, D-E-G and hit tab and it'll show you the possible values
|
||
|
|
available to you and you look in those values and you'll see something like D-E-G for
|
||
|
|
degree.
|
||
|
|
You'll also say D-E-G-C and D-E-G-F and you might think, oh, well, I'll type in 100.
|
||
|
|
100, D-E-G-C and hit enter and then I'll just type in D-E-G-F and I'll get 100 degrees
|
||
|
|
Celsius converted to what it is in Fahrenheit and the return value is 180.
|
||
|
|
And you'll be, whoa, no, no, no, no, wait, 100 degrees Celsius should equal to 112 degrees
|
||
|
|
Fahrenheit.
|
||
|
|
That's the temperature water boils at.
|
||
|
|
Why is that not working?
|
||
|
|
Well, that's because you have to make sure you understand the correct units and how to
|
||
|
|
input those units.
|
||
|
|
Now, for instance, what we actually received here wasn't a conversion of degrees Celsius
|
||
|
|
to Fahrenheit that you expect.
|
||
|
|
What we actually received was this.
|
||
|
|
When there is a temperature degree change of 100 degrees Celsius, that is equivalent
|
||
|
|
to a temperature change of 180 degrees Fahrenheit.
|
||
|
|
That doesn't mean 100 degrees Celsius equals 180 degrees Fahrenheit.
|
||
|
|
That just means that a temperature change of 100 degrees Celsius is equivalent to a temperature
|
||
|
|
change of 180 degrees Fahrenheit, just be aware of that.
|
||
|
|
That's kind of what that means.
|
||
|
|
What you're looking for is to convert Fahrenheit into Celsius in the Fahrenheit.
|
||
|
|
Well, that's a little different because then you have to type in temp Celsius and then
|
||
|
|
parentheses put the number 100 and then it asks you what the conversion you want is temp
|
||
|
|
Fahrenheit.
|
||
|
|
When you hit enter, you get 212.
|
||
|
|
That is not clear.
|
||
|
|
That's because it's not a what units cause a linear conversion.
|
||
|
|
It's more of a functional conversion and you have to put it in a functional notation format
|
||
|
|
like that.
|
||
|
|
There's a lot of caveats to units that will trip you up, but you can easily rectify
|
||
|
|
that by just perusing the man page or even the info page, which is really really nice,
|
||
|
|
but there's some caveats there.
|
||
|
|
A lot of the stuff that you might want to do feet to inches and just the miles, kilometers
|
||
|
|
to inches, stuff like that, pretty straightforward, but if you want to get into more esoteric
|
||
|
|
things like temperature or even converting between megabits or I'm saying megabytes, megabits
|
||
|
|
is fairly simple, but megabytes and gigabytes and gigabytes and stuff, not a straightforward.
|
||
|
|
For instance, again, talking about kilobytes, that uses a specific notation.
|
||
|
|
You look in there and if you were to say, well, if I want to convert 10 gigabytes to
|
||
|
|
kilobytes, how do I do that?
|
||
|
|
If you type in 10GIB and hit enter and hit KIB for kilobytes, it gives you the correct
|
||
|
|
value.
|
||
|
|
The odd thing about that is if you type in 10 and then GI and hit tab for completion,
|
||
|
|
it will complete and if you actually type in a capital G, you would see GI in there and
|
||
|
|
then you would think, okay, I'm going to do MI, you're not going to get the same value,
|
||
|
|
okay?
|
||
|
|
You're going to get some weird number that says 7.9577472A as opposed to 10485760, which is
|
||
|
|
what is that?
|
||
|
|
That is going to be 10485,760 kilobytes as opposed to, you know, in 10GIB, so units
|
||
|
|
has a specific notation that you need to use and you could find out a lot of this stuff
|
||
|
|
by perusing the definitions file and where is the definitions file?
|
||
|
|
Well, that's pretty simple.
|
||
|
|
You can find that quite easily, but before I tell you how to find some of this stuff out,
|
||
|
|
you might be wondering, how do I get out of units once you're in it?
|
||
|
|
That's pretty simple.
|
||
|
|
Hit the control C key, it takes you right out of units.
|
||
|
|
Very simple.
|
||
|
|
Now, to find the definitions list or units, definitions.units is what the name of it is.
|
||
|
|
You just type in units and then the switch, dash capital V for a version information and
|
||
|
|
it's going to tell you the version of units, whether it was compiled with re-line, it's
|
||
|
|
going to tell you what locale support it's been compiled with or what it's using, and
|
||
|
|
then it's going to tell you the units database, which will probably be in slash user slash
|
||
|
|
share slash units and be called slash definitions.units.
|
||
|
|
If you use less or more whatever page you like to use and open that file up and start
|
||
|
|
looking in there, you'll see all the different units available and a lot of really good information
|
||
|
|
about how those units are defined.
|
||
|
|
It's really, really good something excellent to read.
|
||
|
|
If you're not sure what a unit is, looking there and it'll tell you exactly what it is,
|
||
|
|
but it's really, it's really great.
|
||
|
|
Now, there's some other switches that we can talk about here for units.units itself has
|
||
|
|
a quiet mode and what quiet does is that's the dash q or dash dash quiet.
|
||
|
|
What quiet will do is it will bring you up and suppress the prompting of the interactive
|
||
|
|
tool.
|
||
|
|
You won't see that initial information and you will not see that you have colon and you
|
||
|
|
want prompts.
|
||
|
|
You'll just type in whatever you want.
|
||
|
|
Compact suppresses the printing of the asterisk and the slash forward slash, but it'll still
|
||
|
|
show you those both of those values.
|
||
|
|
The dash L or dash dash one line will show you the first line of the output, but it'll
|
||
|
|
suppress the inversion of the conversion.
|
||
|
|
Now, sometimes a lot of those are handy for a cover that in a second, but those three
|
||
|
|
values are all combined in the dash T or dash dash Terse option, which combines quiet,
|
||
|
|
compact and one line all at once.
|
||
|
|
That might be the most handy for when you want to use units without an interactive mode.
|
||
|
|
That's just by typing units and then if you want to do any switches and then followed
|
||
|
|
by in double quotes, what you have, like for instance we talked to 15 feet, you type
|
||
|
|
in 15 space feet, double quotes, closes it, and then space and what you want and then
|
||
|
|
inches.
|
||
|
|
And that'll convert 15 feet into 180 inches.
|
||
|
|
And if you didn't supply any switches, you're going to get the output just like if you were
|
||
|
|
an interactive mode, except it's going to show you currency exchange rates from line and
|
||
|
|
then it's going to show you the asterisk 180.
|
||
|
|
And then the next line, the forward slash 0.0055555556, which is the inversion conversion
|
||
|
|
maybe.
|
||
|
|
So that's interactive or you don't have to go into interactive mode right there.
|
||
|
|
Now, if you were to use the dash T option there, the units dash T, double quotes 15 feet,
|
||
|
|
close the double quotes and then space inches, all you're going to get back is the value
|
||
|
|
of 180 right there.
|
||
|
|
Now you might want to use units with the dash V or dash dash for both mode, which is kind
|
||
|
|
of nice because if we did that same conversion with the dash V instead of it just saying 180,
|
||
|
|
it would produce the output 15 feet equals 180 inches.
|
||
|
|
So it provides a little more robustity to the output, which can be quite nice.
|
||
|
|
Now, units is a monster of a program and has just like BC, an incredible amount of functionality.
|
||
|
|
If you really want to delve into the units command, head on into the man page and the info
|
||
|
|
pages thoroughly explains all this stuff.
|
||
|
|
If you just want to do a simple conversions, you know, you can do that based upon the information
|
||
|
|
I provided you here.
|
||
|
|
But to get involved in more of the esoteric to the units command and the switches and
|
||
|
|
what you can and cannot do, well, I'll say what you can do because there's not a lot
|
||
|
|
you cannot do in the units.
|
||
|
|
You really need to read the man page in this far more detailed cover than in here.
|
||
|
|
If you're scientifically minded and mathematically minded in that way to get the conversions
|
||
|
|
and functions that you can do with units.
|
||
|
|
This has been episode 26 of Linux in the Shell.
|
||
|
|
My name is Dan Washco and I thank you for listening.
|
||
|
|
Join us again for some more Linux in the Shell goodness.
|
||
|
|
And make sure you head on over to the website if you have not already to read the right
|
||
|
|
up and watch the video of this command.
|
||
|
|
That's Linux in the Shell.org.
|
||
|
|
Thank you and have a great day.
|
||
|
|
You have been listening to Hacker Public Radio at HackerPublicRadio.org.
|
||
|
|
We are a community podcast network that releases shows every weekday Monday through Friday.
|
||
|
|
Today's show, like all our shows, was contributed by a HPR listener like yourself.
|
||
|
|
If you ever consider recording a podcast, then visit our website to find out how easy
|
||
|
|
it really is.
|
||
|
|
HackerPublic Radio was founded by the digital dog pound and the infonomicom computer
|
||
|
|
cloud.
|
||
|
|
HPR is funded by the binary revolution at binref.com, all binref projects are proudly sponsored
|
||
|
|
by LinoPages.
|
||
|
|
From shared hosting to custom private clouds, go to LinoPages.com for all your hosting needs.
|
||
|
|
Unless otherwise stasis, today's show is released under a creative commons, attribution,
|
||
|
|
share a like, read also online.
|