info > numfmt

πŸ”’ 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.

πŸš€ Quick Reference

Use CaseCommandDescription
πŸ”’ Convert to SI (human-readable)numfmt --to=si 500000Converts 500000 β†’ 500K
πŸ”’ Convert to IEC (binary)numfmt --to=iec 500000Converts 500000 β†’ 489K
πŸ”’ Convert from SInumfmt --from=si 1MConverts 1M β†’ 1000000
πŸ”’ Convert from IECnumfmt --from=iec 1MConverts 1M β†’ 1048576
πŸ”’ Auto-detect SI/IEC inputnumfmt --from=auto 1MiInterprets Mi as Mebi (1048576)
πŸ“‚ Convert specific field from pipels -log | numfmt --field 3 --header --to=siConverts file sizes (field 3) to SI
πŸ“Š Convert with paddingdu -s * | numfmt --to=si --padding=10Right-aligns output to 10 characters
πŸ“Š Group digits with localenumfmt --from=iec --grouping 2GOutputs 2,147,483,648 (in en_US)
πŸ“ Custom unit sizenumfmt --from-unit=512 10Input 10 represents 10 units of 512 bytes
🏷️ Add suffixnumfmt --to=si --suffix=B 1MOutputs 1MB

βš™οΈ General Options

πŸ” Debugging

--debug β€” Print (to standard error) warning messages about possible erroneous usage.

πŸ”€ Input/Output Formatting

πŸ“ Scaling & Units

πŸ”„ Rounding

--round=METHOD β€” Round numbers according to METHOD: up, down, from-zero (default), towards-zero, nearest.

⚠️ Error Handling

--invalid=MODE β€” Action on input errors:

πŸ“ Possible UNITs

The following UNIT options are available with --from=UNITS and --to=UNITS:

🚫 NONE

No scaling performed. No suffixes accepted for input. All digits printed for output.

πŸ“ SI (International System)

Auto-scale according to SI standard. Input accepts suffixes; output values >1000 rounded with suffix:

πŸ’Ύ IEC (International Electrotechnical Commission, single letter)

Auto-scale according to IEC standard. Values >1024 rounded with suffix (single letter, non-standard but common):

πŸ”€ IEC-I (International Electrotechnical Commission, two-letter standard)

Auto-scale according to IEC standard. Values >1024 rounded with suffix (two-letter, standard compliant):

πŸ€– AUTO

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.

πŸ’‘ Examples of using numfmt

πŸ”’ Converting a single number from/to human representation

$ 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

πŸ”„ Converting from SI to IEC scales

πŸ“Œ 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

πŸ“‚ Converting a single field from piped input

πŸ“Œ 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

πŸ“ Output padding and formatting

# 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

🌍 Locale-aware grouping

$ 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==

πŸšͺ Exit Codes

numfmt
πŸ”’ numfmt: Reformat Numbers πŸš€ Quick Reference βš™οΈ General Options
πŸ” Debugging πŸ”€ Input/Output Formatting πŸ“ Scaling & Units πŸ”„ Rounding ⚠️ Error Handling
πŸ“ Possible UNITs
🚫 NONE πŸ“ SI (International System) πŸ’Ύ IEC (International Electrotechnical Commission, single letter) πŸ”€ IEC-I (International Electrotechnical Commission, two-letter standard) πŸ€– AUTO
πŸ’‘ Examples of using numfmt
πŸ”’ Converting a single number from/to human representation πŸ”„ Converting from SI to IEC scales πŸ“‚ Converting a single field from piped input πŸ“ Output padding and formatting 🌍 Locale-aware grouping
πŸšͺ Exit Codes

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)
Valid XHTML 1.0 Transitional!Valid CSS!
Enhanced by LLM: deepseek-v4-flash / taotoken.net / www.chedong.com - original format

^_top_^