numfmt: Reformat Numbersπ numfmt reads numbers in various representations and reformats them as requested. The most common usage is converting numbers to/from human representation (e.g. 4G β¦ 4,000,000,000).
numfmt [OPTION]... [NUMBER]
π numfmt converts each NUMBER on the command-line according to the specified options. If no NUMBERs are given, it reads numbers from standard input. numfmt can optionally extract numbers from specific columns, maintaining proper line padding and alignment.
β
An exit status of zero indicates success, and a nonzero value indicates failure. See --invalid for additional information regarding exit status.
| Use Case | Command | Description |
|---|---|---|
| π’ Convert to SI (human-readable) | numfmt --to=si 500000 | Converts 500000 β 500K |
| π’ Convert to IEC (binary) | numfmt --to=iec 500000 | Converts 500000 β 489K |
| π’ Convert from SI | numfmt --from=si 1M | Converts 1M β 1000000 |
| π’ Convert from IEC | numfmt --from=iec 1M | Converts 1M β 1048576 |
| π’ Auto-detect SI/IEC input | numfmt --from=auto 1Mi | Interprets Mi as Mebi (1048576) |
| π Convert specific field from pipe | ls -log | numfmt --field 3 --header --to=si | Converts file sizes (field 3) to SI |
| π Convert with padding | du -s * | numfmt --to=si --padding=10 | Right-aligns output to 10 characters |
| π Group digits with locale | numfmt --from=iec --grouping 2G | Outputs 2,147,483,648 (in en_US) |
| π Custom unit size | numfmt --from-unit=512 10 | Input 10 represents 10 units of 512 bytes |
| π·οΈ Add suffix | numfmt --to=si --suffix=B 1M | Outputs 1MB |
--debug β Print (to standard error) warning messages about possible erroneous usage.
-d D, --delimiter=D β Use character D as input field separator (default: whitespace). β οΈ Note: Using non-default delimiter turns off automatic padding.--field=FIELDS β Convert the number in input field FIELDS (default: 1). Supports cut style field ranges:
N β N'th field, counted from 1N- β from N'th field, to end of lineN-M β from N'th to M'th field (inclusive)-M β from first to M'th field (inclusive)- β all fields--format=FORMAT β Use printf-style floating FORMAT string. Must contain one %f directive, optionally with ', -, 0, width or precision modifiers. The ' modifier enables --grouping, - enables left-aligned --padding, width enables right-aligned --padding. 0 width modifier generates leading zeros. Precision like %.1f overrides auto-scaling precision.--grouping β Group digits in output numbers according to the current locale's grouping rules (e.g. thousands separator). No effect in POSIX/C locale.--header[=N] β Print the first N (default: 1) lines without any conversion.--padding=N β Pad output numbers to N characters by adding spaces. Positive N = right-aligned, negative N = left-aligned. Default: automatic alignment based on input line width (only with default delimiter).--suffix=SUFFIX β Add SUFFIX to output numbers, and accept optional SUFFIX in input numbers.-z, --zero-terminated β Delimit items with a zero byte (ASCII NUL) rather than newline. Useful with perl -0, find -print0, xargs -0. Note: with -z, newline is treated as a field separator.--from=UNIT β Auto-scale input numbers according to UNIT. Default: no scaling (suffixes trigger error).--from-unit=N β Specify input unit size (default: 1). Use when input represents other units (e.g. --from-unit=512 for 512-byte blocks). Suffixes handled as with --from=auto.--to=UNIT β Auto-scale output numbers according to UNIT. Default: no scaling (all digits printed).--to-unit=N β Specify output unit size (default: 1). E.g. --to=si --to-unit=1000 for 1KB blocks. Suffixes handled as with --from=auto.--round=METHOD β Round numbers according to METHOD: up, down, from-zero (default), towards-zero, nearest.
--invalid=MODE β Action on input errors:
abort (default) β Exit immediately with status 2fail β Print warning for each error, exit with status 2warn β Print warning, exit with status 0ignore β No diagnostics, exit with status 0The following UNIT options are available with --from=UNITS and --to=UNITS:
No scaling performed. No suffixes accepted for input. All digits printed for output.
Auto-scale according to SI standard. Input accepts suffixes; output values >1000 rounded with suffix:
K β 1000ΒΉ = 10Β³ (Kilo)M β 1000Β² = 10βΆ (Mega)G β 1000Β³ = 10βΉ (Giga)T β 1000β΄ = 10ΒΉΒ² (Tera)P β 1000β΅ = 10ΒΉβ΅ (Peta)E β 1000βΆ = 10ΒΉβΈ (Exa)Z β 1000β· = 10Β²ΒΉ (Zetta)Y β 1000βΈ = 10Β²β΄ (Yotta)Auto-scale according to IEC standard. Values >1024 rounded with suffix (single letter, non-standard but common):
K β 1024ΒΉ = 2ΒΉβ° (Kibi)M β 1024Β² = 2Β²β° (Mebi)G β 1024Β³ = 2Β³β° (Gibi)T β 1024β΄ = 2β΄β° (Tebi)P β 1024β΅ = 2β΅β° (Pebi)E β 1024βΆ = 2βΆβ° (Exbi)Z β 1024β· = 2β·β° (Zebi)Y β 1024βΈ = 2βΈβ° (Yobi)Auto-scale according to IEC standard. Values >1024 rounded with suffix (two-letter, standard compliant):
Ki β 1024ΒΉ = 2ΒΉβ° (Kibi)Mi β 1024Β² = 2Β²β° (Mebi)Gi β 1024Β³ = 2Β³β° (Gibi)Ti β 1024β΄ = 2β΄β° (Tebi)Pi β 1024β΅ = 2β΅β° (Pebi)Ei β 1024βΆ = 2βΆβ° (Exbi)Zi β 1024β· = 2β·β° (Zebi)Yi β 1024βΈ = 2βΈβ° (Yobi)Only usable with --from. Numbers with K,M,G,T,P,E,Z,Y suffixes interpreted as SI values; numbers with Ki,Mi,Gi,Ti,Pi,Ei,Zi,Yi suffixes interpreted as IEC values.
numfmt$ numfmt --to=si 500000
500K
$ numfmt --to=iec 500000
489K
$ numfmt --to=iec-i 500000
489Ki
$ numfmt --from=si 1M
1000000
$ numfmt --from=iec 1M
1048576
# with '--from=auto', M=Mega, Mi=Mebi
$ numfmt --from=auto 1M
1000000
$ numfmt --from=auto 1Mi
1048576
π E.g. when a harddisk capacity is advertised as 1TB, but the drive's capacity gives lower values:
$ numfmt --from=si --to=iec 1T
932G
π These examples are for demonstration purposes β both ls and df support --human-readable natively.
# Third field (file size) will be shown in SI representation
$ ls -log | numfmt --field 3 --header --to=si | head -n4
-rw-r--r-- 1 94K Aug 23 2011 ABOUT-NLS
-rw-r--r-- 1 3.7K Jan 7 16:15 AUTHORS
-rw-r--r-- 1 36K Jun 1 2011 COPYING
-rw-r--r-- 1 0 Jan 7 15:15 ChangeLog
# Second field (size) will be shown in IEC representation
$ df --block-size=1 | numfmt --field 2 --header --to=iec | head -n4
File system 1B-blocks Used Available Use% Mounted on
rootfs 132G 104741408 26554036 80% /
tmpfs 794M 7580 804960 1% /run/shm
/dev/sdb1 694G 651424756 46074696 94% /home
# Pad to 10 characters, right-aligned
$ du -s * | numfmt --to=si --padding=10
2.5K config.log
108 config.status
1.7K configure
20 configure.ac
# Pad to 10 characters, left-aligned
$ du -s * | numfmt --to=si --padding=-10
2.5K config.log
108 config.status
1.7K configure
20 configure.ac
# Pad to 10 characters, left-aligned, using 'format'
$ du -s * | numfmt --to=si --format="%10f"
2.5K config.log
108 config.status
1.7K configure
20 configure.ac
# Pad to 10 characters, left-aligned, using 'format'
$ du -s * | numfmt --to=si --padding="%-10f"
2.5K config.log
108 config.status
1.7K configure
20 configure.ac
$ LC_ALL=C numfmt --from=iec --grouping 2G
2147483648
$ LC_ALL=en_US.utf8 numfmt --from=iec --grouping 2G
2,147,483,648
$ LC_ALL=ta_IN numfmt --from=iec --grouping 2G
2,14,74,83,648
$ LC_ALL=C ./src/numfmt --from=iec --format="==%'15f==" 2G
== 2147483648==
$ LC_ALL=en_US.utf8 ./src/numfmt --from=iec --format="==%'15f==" 2G
== 2,147,483,648==
$ LC_ALL=en_US.utf8 ./src/numfmt --from=iec --format="==%'-15f==" 2G
==2,147,483,648 ==
$ LC_ALL=ta_IN ./src/numfmt --from=iec --format="==%'15f==" 2G
== 2,14,74,83,648==
0 β Success2 β Error (invalid input, conversion error, etc.)Generated by phpman v4.9.26-1-g511901d · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-07-31 12:49 @216.73.217.152
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Enhanced by LLM: deepseek-v4-flash / taotoken.net / www.chedong.com - original format