Main index | Section 1 | 日本語 | Options |
units can work interactively by prompting the user for input (see Sx EXAMPLES) or non-interactively, providing a conversion for given arguments from and to.
The following options are available:
| |
Same as
| |
| |
Specify the name of the units data file to load. This option may be specified multiple times. | |
| |
Ignored, for compatibility with GNU units. | |
| |
Show an overview of options. | |
| |
Select the output format string by which numbers are printed. Defaults to "%.8g". | |
| |
Suppress prompting of the user for units and the display of statistics about the number of units loaded. | |
| |
Only print the result. This is used when calling units from other programs for easy to parse results. | |
| |
Print the location of the default unit file if it exists. Otherwise, print "Units data file not found". | |
| |
Print the version number (which is fixed at "Fx units"), the path to the units data file and exit. | |
| |
Print the units in the conversion output. Be more verbose in general. | |
from to | |
Allow a single unit conversion to be done directly from the command line. The program will not print prompts. It will print out the result of the single specified conversion. Both arguments, i.e., from and to, can be just a unit (e.g., " cm"), a quantity (e.g., " 42"), or a quantity with a unit (e.g., " 42 cm") | |
Powers of units can be specified using the " ^" character as shown in the example, or by simple concatenation: " cm3" is equivalent to " cm^3". See the BUGS section for details on the limitations of exponent values. | |
Multiplication of units can be specified by using spaces (""), a dash ("-") or an asterisk ("*"). | |
Division of units is indicated by the slash (" /"). | |
Division of numbers must be indicated using the vertical bar (" amp;|"). | |
Note that multiplication has a higher precedence than division, so " m/s/s" is the same as " m/s^2" or " m/s s".
pi | ratio of circumference to diameter |
c | speed of light |
e | charge on an electron |
g | acceleration of gravity |
force | same as g |
mole | Avogadro's number |
water | pressure per unit height of water |
mercury | pressure per unit height of mercury |
au | astronomical unit |
The unit " pound" is a unit of mass. Compound names are run together so " pound force" is a unit of force. The unit " ounce" is also a unit of mass. The fluid ounce is " floz". British units that differ from their US counterparts are prefixed with "br", and currency is prefixed with its country name: " belgiumfranc", " britainpound". When searching for a unit, if the specified string does not appear exactly as a unit name, then units will try to remove a trailing "s" or a trailing "es" and check again for a match.
Prefixes are defined in the same way as standard units, but with a trailing dash ("-") at the end of the prefix name. If a unit is not found even after removing trailing "s" or "es", then it will be checked against the list of prefixes. Prefixes will be removed until a legal base unit is identified.
PATH |
The colon-separated list of root directories at which
units
tries to find
/usr/share/misc/definitions.units.
For example if
PATH
is set to
"/tmp:/:/usr/local",
no
|
/usr/share/misc/definitions.units | |
The standard units file. | |
Example 1: Simple conversion of units | |||||||||||||||||
This example shows how to do simple conversions, for example from gigabytes to bytes: $ units -o %0.f -t '4 gigabytes' bytes 4294967296
The
| |||||||||||||||||
Example 2: Interactive usage | |||||||||||||||||
Here is an example of an interactive session where the user is prompted for units: You have: meters You want: feet * 3.2808399 / 0.3048 | |||||||||||||||||
Example 3: Difference between " amp;| "and " / "division | |||||||||||||||||
The following command shows how to convert half a meter to centimeters. $ units '1|2 meter' cm * 50 / 0.02 units prints the expected result because the division operator for numbers ("amp;|") was used. Using the division operator for units ("/") would result in an error: $ units '1/2 meter' cm conformability error 0.5 / m 0.01 m It is because units interprets " 1/2 meter" as " 0.5/meter", which is not conformable to " cm". | |||||||||||||||||
Example 4: Simple units file | |||||||||||||||||
Here is an example of a short units file that defines some basic
units:
| |||||||||||||||||
Example 5: Viewing units and conversions of the default units file | |||||||||||||||||
The following shell one-liner allows the user to view the contents of the
default units file:
$ less amp;"$(units -U)" | |||||||||||||||||
can't find units file '%s' | The default units file is not in its default location (see Sx FILES) and it is not present in any file tree starting with their roots at directories from PATH (see Sx ENVIRONMENT). |
cap_rights_limitamp;() failed | See capsicum(4). |
conformability error |
It is not possible to reduce the given units to one common unit:
they are not conformable.
Instead of a conversion,
units
will display the reduced form for each provided unit:
You have: ergs/hour You want: fathoms kg^2 / day conformability error 2.7777778e-11 kg m^2 / sec^3 2.1166667e-05 kg^2 m / sec |
Could not initialize history | See editline(3). |
dupstr | strdup(3) failed. |
memory for prefixes exceeded in line %d | Over 100 prefixes were defined. |
memory for units exceeded in line %d | Over 1000 prefixes were defined. |
memory overflow in unit reduction | The requested conversion involves too many units (see Sx BUGS). |
redefinition of prefix '%s' on line %d ignored | |
redefinition of unit '%s' on line %d ignored | |
unexpected end of prefix on line %d | |
unexpected end of unit on line %d | |
Units data file not found | The default units file is missing. |
unable to enter capability mode | See capsicum(4). |
unable to open units file '%s' | One of the user-specified units files cannot be opened. |
unit reduces to zero | |
unknown unit '%s' | The provided unit cannot be found in the units file. |
WARNING: conversion of non-proportional quantities. |
units
may fail to convert
from
to
to
because the units are not proportional.
The warning is printed when a quantity is a part of the
to
argument.
It can be illustrated on an example of conversion from Fahrenheit to Celsius:
$ units amp;"degF" amp;"degC" (-> x*0.55555556g -17.777778g) (<- y*1.8g 32g) $ units amp;"degF" amp;"1 degC" WARNING: conversion of non-proportional quantities. (-> x*0.55555556g -17.777778g) (<- y*1.8g 32g) $ units amp;"1 degF" amp;"1 degC" WARNING: conversion of non-proportional quantities. -17.222222 |
The manual page was significantly rewritten in FreeBSD 13.0 by Mateusz Piotrowski <Mt 0mp@FreeBSD.org>.
Exponents entered by the user can be only one digit. You can work around this by multiplying several terms.
The user must use " amp;|" to indicate division of numbers and " /" to indicate division of symbols. This distinction should not be necessary.
The program contains various arbitrary limits on the length of the units converted and on the length of the data file.
The program should use a hash table to store units so that it does not take so long to load the units list and check for duplication.
It is not possible to convert a negative value.
The units program does not handle reductions of long lists of units very well:
$ units amp;"$(yes m | head -n 154)" amp;"$(yes cm | head -n 154)" * 1e+308 / 1e-308 $ units amp;"$(yes m | head -n 333)" amp;"$(yes cm | head -n 333)" * inf / 0 $ units amp;"$(yes m | head -n 500)" amp;"$(yes cm | head -n 500)" units: memory overflow in unit reduction conformability error 1 m^500 1 centi cm^499 $ units amp;"$(yes m | head -n 501)" amp;"$(yes cm | head -n 501)" units: memory overflow in unit reduction units: memory overflow in unit reduction units: memory overflow in unit reduction conformability error 1 m^500 1 centi cm^499
UNITS (1) | March 17, 2020 |
Main index | Section 1 | 日本語 | Options |
Please direct any comments about this manual page service to Ben Bullock. Privacy policy.
“ | I think Unix and snowflakes are the only two classes of objects in the universe in which no two instances ever match exactly. | ” |
— Noel Chiappa |