How to convert units using command-line

Use dedicated command-line utility to convert various units to different measurement systems.


Install units package.

$ sudo apt install units


Convert a fraction of MiB to KiB.

$ units --verbose --one-line "3|4MiB" "KiB"
        3|4MiB = 768 KiB

Convert of MiB to GiB.

$ units --verbose --one-line "1024MiB" "GiB"
        1024MiB = 1 GiB

Convert of GB to MB.

$ units --verbose --one-line "1 GB" "MB"
        1 GB = 1000 MB

Convert of MB to GiB.

$ units --verbose --one-line "1000MB" "GiB"
         1000MB = 0.93132257 GiB

Convert MB/s to GB/hour.

$ units --verbose --one-line "10MB/sec" "GB/hour"
        10MB/sec = 36 GB/hour

Convert of seconds to days.

$ units --verbose --one-line "216000 secs" "days"
        216000 secs = 2.5 days

Convert temperature.

$ units --verbose  "tempC(23)" "tempF"
         tempC(23) = tempF(73.4)

Convert currency.

$ units --verbose --one-line "1$" "PLN"
        1$ = 3.7540515 PLN

Perform complex conversion.

$ units --verbose --one-line "29$/5m" "$/m"
        29$/5m = 5.8 $/m

Define output format and use terse output

$ units --terse --output-format %.1f  "113964KiB" "MiB"

Additional information

Inspect /usr/share/units/definitions.units to define new units and /usr/share/units/currency.units to update currency exchange rates.