numfmt(1)
Convert numbers to or from human-readable formats (e.g., 1K, 2M, 3G).
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
| Flag | What it does |
|---|---|
--from=UNIT | Interpret input as human-readable format; UNIT is auto, si, iec, iec-i (e.g., --from=iec for 1K=1024) |
--to=UNIT | Output in human-readable format; UNIT is auto, si, iec, iec-i (default is auto) |
--format=FORMAT | Use printf-style format string for output, e.g., '%.2f' for 2 decimal places |
--round=METHOD | Rounding method: up, down, from-zero, towards-zero, nearest (default) |
--suffix=SUFFIX | Append a string to each output number (e.g., --suffix=' bytes') |
--padding=WIDTH | Pad output numbers to WIDTH characters (right-aligned by default) |
--zero | Pad with leading zeros instead of spaces |
--grouping | Group digits with thousands separators (commas by default) |
--field=N | Process only field N in each input line (whitespace-delimited) |
--header | Skip the first line of input (treat as header) |
Examples
Convert 1000000 to SI format: outputs 1.0M
echo 1000000 | numfmt --to=siParse 1M (SI) back to decimal: outputs 1000000
echo 1M | numfmt --from=siConvert to IEC binary format (1024-based): outputs 1.0Mi
echo 1048576 | numfmt --to=iecOutput with 1 decimal place: 5.5M
numfmt --to=si --format='%.1f' <<< 5500000Process multiple numbers from stdin: outputs 1.0K, 2.0K, 3.0K
echo -e '1000\n2000\n3000' | numfmt --to=siAdd a suffix to output: 1.0M bytes
numfmt --to=si --suffix=' bytes' <<< 1024000Convert 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