units

utilitiesLinux/Unix
The units command is one of the most frequently used commands in Linux/Unix-like operating systems. units Convert quantities between different units

Quick Reference

Command Name:

units

Category:

utilities

Platform:

Linux/Unix

Basic Usage:

units [options] [arguments]

Common Use Cases

    Syntax

    units [options] [from-unit [to-unit]]

    Options

    Option Description
    -c, --check Check that all units and prefixes are defined
    -o, --output-format FORMAT Specify the output format: one of 'default', 'compact', or 'raw'
    -f, --file FILE Specify units data file
    -p, --product PRODUCT Print product of converted unit and NUMBER
    -r, --round ROUND Round output to ROUND digits (default is 12)
    -s, --strict Apply strict conversion rules
    -t, --terse Display terse output (conversion factor only)
    -v, --verbose Display verbose output (unit definitions)
    -1, --one-line Display output on one line
    -q, --quiet Suppress prompting
    -h, --help Display help and exit
    -V, --version Print version information and exit

    Examples

    How to Use These Examples

    The examples below show common ways to use the units command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.

    Basic Examples:

    Interactive mode
    units
    Convert 5 kilometers to miles
    units "5 kilometers" miles
    Convert 100 degrees Celsius to Fahrenheit
    units "100 celsius" fahrenheit
    Convert 1 hour to seconds
    units "1 hour" seconds

    Advanced Examples:

    Convert currency (assuming updated currency database)
    units "100 USD" EUR
    Convert data storage units
    units "1 gigabyte" "megabits"
    Area conversion
    units "1 acre" "square meters"
    Speed conversion
    units "60 mph" "km/h"
    Power conversion
    units "1 horsepower" "watts"
    Pressure conversion
    units "1 atmosphere" "psi"
    Fuel efficiency conversion
    units "30 mpg" "km/liter"
    Complex conversions
    units "5 newtons * 2 meters" "joules"
    Using with pipes in a script
    echo "15 stones" | units -t "pounds"
    Get conversion factor only (no conversion)
    units -t "meter" "inch"
    Showing the unit definitions
    units -v "watt"
    Using with non-standard units file
    units -f /path/to/custom/units.dat "furlong/fortnight" "m/s"

    Try It Yourself

    Practice makes perfect! The best way to learn is by trying these examples on your own system with real files.

    Understanding Syntax

    Pay attention to the syntax coloring: commands, options, and file paths are highlighted differently.

    Notes

    The `units` command is a powerful unit conversion utility available in Unix-like operating systems, including Linux. It allows users to convert quantities between different units of measurement across a wide range of physical quantities, including length, mass, volume, time, temperature, pressure, energy, power, and many more. At its core, `units` operates on a database of unit definitions, typically stored in `/usr/share/units/definitions.units` or similar locations depending on the distribution. This database contains thousands of units and conversion factors, making it one of the most comprehensive unit conversion tools available on the command line. **Key features of the `units` command include:** 1. **Interactive Mode**: When run without arguments, `units` enters an interactive mode where it prompts for the unit to convert from and the unit to convert to, allowing for multiple conversions in a single session. 2. **Command Line Conversion**: Users can specify both the input and output units directly on the command line for quick, one-off conversions. 3. **Mathematical Operations**: The command supports mathematical operations within unit specifications, allowing for complex conversions like "5 meters / 2 seconds" to "miles per hour". 4. **Dimensional Analysis**: The `units` command performs dimensional analysis to ensure that conversions are valid. For example, it won't allow conversion from length to mass unless appropriate conversion factors are specified. 5. **Custom Unit Definitions**: Users can create custom unit definition files with the `-f` option, allowing for specialized or local units not included in the standard database. 6. **Currency Conversion**: Some versions include currency conversion capabilities, though these may require updates to maintain accuracy with current exchange rates. **Usage scenarios include:** - **Scientific and Engineering Work**: Converting between different unit systems (metric, imperial, etc.) in scientific calculations. - **International Communication**: Translating measurements between regional standards (e.g., Celsius to Fahrenheit for temperature discussions with international colleagues). - **Cooking and Recipes**: Converting between volume and weight measures, or between different countries' conventions. - **Travel Planning**: Converting foreign currencies, distances, or fuel efficiency measures. - **Educational Purposes**: Teaching students about unit conversions and dimensional analysis. The `units` command can handle remarkably complex conversions that would be difficult to compute manually, such as converting from "acre-feet" to "cubic meters" or from "kilowatt-hours" to "BTUs". For developers, the command can be easily integrated into scripts using options like `-t` (terse output) to get just the conversion factor without additional text. While `units` is extremely versatile, users should be aware that some specialized scientific or industry-specific units might not be included in the standard definitions file. In such cases, defining custom units may be necessary. Overall, the `units` command represents an essential tool for anyone working with physical quantities across different unit systems, providing accurate conversions with minimal effort.

    Related Commands

    These commands are frequently used alongside units or serve similar purposes:

    Use Cases

    Learn By Doing

    The best way to learn Linux commands is by practicing. Try out these examples in your terminal to build muscle memory and understand how the units command works in different scenarios.

    $ units
    View All Commands