units - macOS
NAME
units – Convert units of measurement
SYNTAX
units
[-a | -b | -c | -d | -e | -f | -g | -j | -k | -m | -n | -N | -t | -w] [-i input] [-o output] [-p precision] [-v value] [–from from_unit] [–to to_unit] [–list] [–version] [–help]
OPTIONS/FLAGS
-a, –angle: Convert angles between degrees, radians, and gradians.
-b, –bandwidth: Convert bandwidth between bits per second, bytes per second, kilobits per second, and megabits per second.
-c, –currency: Convert between various currencies using exchange rates.
-d, –data: Convert between various data units, including bits, bytes, kilobytes, megabytes, and gigabytes.
-e, –energy: Convert between different energy units, such as joules, calories, and electronvolts.
-f, –frequency: Convert between various units of frequency, including hertz, kilohertz, and megahertz.
-g, –gravity: Convert between units of acceleration due to gravity, including standard gravity, lunar gravity, and Martian gravity.
-h, –help: Display the help text and exit.
-i, –input: Input value to be converted.
-j, –length: Convert between different units of length, including inches, feet, yards, miles, and kilometers.
-k, –mass: Convert between various units of mass, including grams, ounces, pounds, and kilograms.
-l, –list: List all supported units and conversion factors.
-m, –pressure: Convert between pressure units, such as pascals, atmospheres, and pounds per square inch.
-n, –number: Convert between different numerical bases, including binary, octal, decimal, and hexadecimal.
-o, –output: Unit to convert to.
-N, –none: Disable unit conversion and simply echo the input value.
-p, –precision: Number of decimal places to display in the result.
-t, –temperature: Convert between different temperature scales, including Celsius, Fahrenheit, and Kelvin.
-v, –value: Value to be converted.
–from: Specify the input unit.
–to: Specify the output unit.
–version: Display the version number and exit.
EXAMPLES
Convert 50 miles to kilometers:
units -j -i 50 miles -o kilometers
Calculate the area of a circle with a radius of 5 inches:
units -j -i 5 inches -o square feet
Convert 100 euros to US dollars:
units -c -i 100 eur -o usd
Convert 1000 bytes to megabits:
units -d -i 1000 bytes -o megabits
COMMON ISSUES
- Incorrect units: Make sure to specify the units correctly, including their singular or plural forms.
- Unsupported conversions: Not all units are supported for conversion. Check the supported units using the
--list
option. - Missing input or output units: Providing both input and output units is required for conversion.
INTEGRATION
Units can be used in combination with other macOS commands to perform complex calculations. For example, you can use it with the awk
command to process data in a script:
awk '{ print units -j -i $1 miles -o kilometers }' data.txt
RELATED COMMANDS
bc
: Arbitrary-precision calculatordc
: Desk calculator