Intro To 'numfmt' Command In Linux
2024-06-01 - By Robert Elder
I use the 'numfmt' command to format numbers that quantify data storage:
echo '1024' | numfmt
1024
echo '1024' | numfmt --to=si
1.1K
echo '1024' | numfmt --to=iec
1.0K
echo '1024' | numfmt --to=iec-i
1.0Ki
A Real-World Use Case
Recently, my YouTube shorts videos haven't been doing well:
![Lower Views](https://blog.robertelder.org/intro-to-numfmt-command/lower-views_600x600_qn_s81801.png)
Kids these days just aren't interested in the same old boring output from the 'ls' command:
ls -l
total 108
-rw-rw-r-- 1 robert robert 54957 May 27 22:58 cat.png
-rw-rw-r-- 1 robert robert 44824 May 27 22:58 main.c
-rw-rw-r-- 1 robert robert 4324 May 27 22:58 README.txt
But I can use the 'numfmt' command to format the output of my commands in such a way that appeals to terminally online people who are obsessed with memes and anime culture:
ls -l | numfmt --field=5 --format="πUΟUπ %4f π₯Ίππ"
total 108
-rw-rw-r-- 1 robert robert πUΟUπ 54957 π₯Ίππ May 27 22:58 cat.png
-rw-rw-r-- 1 robert robert πUΟUπ 44824 π₯Ίππ May 27 22:58 main.c
-rw-rw-r-- 1 robert robert πUΟUπ 4324 π₯Ίππ May 27 22:58 README.txt
![Anime Memes](https://blog.robertelder.org/intro-to-numfmt-command/anime-meme_600x600_qn_s212737.png)
The '--format' flag allows me to specify how the size quantity is represented, and the '--field' flag specifies which columns are to be formatted.
Format Sizes In SI or IEC Representation
I can also use the '--to' flag to represent the file size in SI, IEC or two letter IEC representation:
numfmt --from=si --to=iec 1M
977K
numfmt --from=si --to=iec 1048576
1.0M
Format Arbitrary Size Quantities
The 'numfmt' command can also accept optional numbers as input as well:
numfmt --from=si --to=iec 1Z
868E
numfmt --from=si --to=iec 1E
889P
numfmt --from=si --to=iec 1P
910T
numfmt --from=si --to=iec 1T
932G
numfmt --from=si --to=iec 1G
954M
numfmt --from=si --to=iec 1M
977K
numfmt --from=si --to=iec 1K
1000
This can be useful for performing inline unit conversions.
Now, all the people with anime profile pictures will press the like button on my videos, and I'll become YouTube famous:
![Anime Profile Picture](https://blog.robertelder.org/intro-to-numfmt-command/anime-profile-picture_600x600_qn_s85873.png)
And that's why the 'numfmt' command is my favourite Linux command.
![]() Intro To 'stty' Command In Linux
Published 2023-10-04 |
![]() $1.00 CAD |
![]() Intro To 'nproc' Command In Linux
Published 2023-07-15 |
![]() Intro To 'comm' Command In Linux
Published 2023-09-06 |
![]() How To Force The 'true' Command To Return 'false'
Published 2023-07-09 |
![]() A Surprisingly Common Mistake Involving Wildcards & The Find Command
Published 2020-01-21 |
![]() A Guide to Recording 660FPS Video On A $6 Raspberry Pi Camera
Published 2019-08-01 |
![]() Intro To 'chroot' Command In Linux
Published 2023-06-23 |
Join My Mailing List Privacy Policy |
Why Bother Subscribing?
|