$linuxjunkies
>

numfmt(1)

Convert numbers to or from human-readable formats (e.g., 1K, 2M, 3G).

UbuntuDebianFedoraArch

Synopsis

numfmt [OPTION]... [NUMBER]...

Description

numfmt converts numbers between plain decimal and human-readable formats with SI or IEC suffixes. It reads numbers from input (stdin or arguments), applies transformations, and outputs the result. Useful for making large numbers readable (1000000 → 1M) or parsing human-readable values back to plain numbers.

By default, numfmt treats input as decimal and outputs with SI suffixes (K=1000). Use --from=iec for binary (1024-based) input and --to=iec for binary output. Handles both floating-point and integer values.

Common options

FlagWhat it does
--from=UNITInterpret input as human-readable format; UNIT is auto, si, iec, iec-i (e.g., --from=iec for 1K=1024)
--to=UNITOutput in human-readable format; UNIT is auto, si, iec, iec-i (default is auto)
--format=FORMATUse printf-style format string for output, e.g., '%.2f' for 2 decimal places
--round=METHODRounding method: up, down, from-zero, towards-zero, nearest (default)
--suffix=SUFFIXAppend a string to each output number (e.g., --suffix=' bytes')
--padding=WIDTHPad output numbers to WIDTH characters (right-aligned by default)
--zeroPad with leading zeros instead of spaces
--groupingGroup digits with thousands separators (commas by default)
--field=NProcess only field N in each input line (whitespace-delimited)
--headerSkip the first line of input (treat as header)

Examples

Convert 1000000 to SI format: outputs 1.0M

echo 1000000 | numfmt --to=si

Parse 1M (SI) back to decimal: outputs 1000000

echo 1M | numfmt --from=si

Convert to IEC binary format (1024-based): outputs 1.0Mi

echo 1048576 | numfmt --to=iec

Output with 1 decimal place: 5.5M

numfmt --to=si --format='%.1f' <<< 5500000

Process multiple numbers from stdin: outputs 1.0K, 2.0K, 3.0K

echo -e '1000\n2000\n3000' | numfmt --to=si

Add a suffix to output: 1.0M bytes

numfmt --to=si --suffix=' bytes' <<< 1024000

Convert only the 2nd field in a line: outputs 'file 2.0M data'

numfmt --field=2 --to=si <<< 'file 2097152 data'

Add thousands separators: outputs 1,000,000 before conversion shows 1.0M

numfmt --to=si --grouping <<< 1000000

Related commands