LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

numfmt

converts numbers to and from human-readable representations

TLDR

Convert bytes to human-readable
$ numfmt --to=iec [1048576]
copy
Convert with IEC units (Ki, Mi, Gi)
$ echo [1073741824] | numfmt --to=iec
copy
Convert with SI units (K, M, G)
$ numfmt --to=si [1000000]
copy
Parse human-readable to number
$ numfmt --from=iec [10M]
copy
Format specific field in input
$ df -B1 | numfmt --header --field 2-4 --to=iec
copy
Add suffix
$ numfmt --to=si --suffix=B [1000000]
copy
Set output padding
$ numfmt --to=iec --padding=10 [1048576]
copy

SYNOPSIS

numfmt [--from=UNIT] [--to=UNIT] [--field=N] [options] [numbers]

DESCRIPTION

numfmt converts numbers to and from human-readable representations. It handles both SI units (powers of 1000: K, M, G) and IEC units (powers of 1024: Ki, Mi, Gi).Input parsing (--from) interprets suffixed numbers: 10K becomes 10000 (SI) or 10240 (IEC). Output conversion (--to) formats numbers with appropriate suffixes for readability.For processing command output, --field selects which column to convert, and --header preserves header rows. This enables piping output from commands like df or ls through numfmt for human-readable conversion.The --format option provides printf-style control: `%10.2f` for fixed-width decimal output. Combined with --grouping, numbers display with locale-appropriate thousands separators.Rounding modes control how fractional values are handled. The default rounds to nearest, but ceiling (up) or floor (down) may be preferred for storage calculations.

PARAMETERS

--from= UNIT

Parse input units (auto, si, iec, iec-i).
--to= UNIT
Convert to units (si, iec, iec-i).
--field= N
Convert field N (default: 1).
--header[=N]
Skip N header lines (default: 1).
--padding= N
Pad output to N characters.
--suffix= STR
Append suffix to output.
--format= FMT
Printf-style format.
--round= METHOD
Rounding: up, down, from-zero, towards-zero, nearest.
--grouping
Use locale digit grouping (e.g., 1,000).
--delimiter= D
Use D as field delimiter.
--invalid= MODE
Handle invalid input: abort, fail, warn, ignore.
-d D
Short for --delimiter.
--debug
Print conversion warnings.

INSTALL

sudo apt install coreutils
copy
sudo dnf install coreutils
copy
sudo pacman -S coreutils
copy
sudo apk add coreutils
copy
sudo zypper install coreutils
copy
brew install coreutils
copy
nix profile install nixpkgs#coreutils
copy

CAVEATS

SI and IEC units differ significantly at large values. The 'iec-i' format uses explicit "Ki" suffix while 'iec' uses just "K". Floating-point precision may affect very large numbers. Not all locales support grouping.

HISTORY

numfmt is part of GNU coreutils, added to provide standardized number formatting across utilities. It addresses the inconsistency of human-readable output between different commands, providing a single tool for number conversion that respects both SI and IEC standards.

SEE ALSO

printf(1), bc(1), units(1), factor(1)

Braincup
Open source brain training for math, memory and focus
Braincup mini-games
41 mini-games · Apache-2.0
No ads · No tracking
Play in browser
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid
276 stars
From the maker of Linux Command Library
Copied to clipboard
Braincup
Open source brain training for math, memory and focus. 41 mini-games, from mental arithmetic to Sudoku, N-Back and Solo Chess.
Apache-2.0 licensed · No ads · No tracking · No account
From the maker of Linux Command Library
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid