Tag Archives: number

number: What computers were made for

I found a lonesome leftover title from bsd-games hiding in my vimwiki directory. This is number, which, if you think about it, does pretty much exactly what it promises.


number takes a series of digits and converts them into written English. It’s a niche application, but one that could come in handy.

By itself, number breaks apart its output line-by-line. If you want a full string, you’ll have to feed it its only flag, -l.

And that’s about it. If you feel like really putting number through its paces, give this a try.

number -l $( < /dev/urandom tr -dc 0-9 | head -c24 )

Things like that are what computers were made for. ๐Ÿ˜‰

numfmt: Saving you a trip to Google

Sometimes people accuse me of misnumbering things when I type “4Mhz” or “64Kb,” because there is a difference in numbering and how the abbreviations are used. Which is true.

In my defense, I’ll say that I adopted the uppercase-lowercase style as a concession to the AP Stylebook, which (last time I checked) doesn’t rule on things like mebibytes. I have other reasons, which are rather boring (skip to the end if you want to know).

Regardless, “Mb” seems to cover the idea for me, and I can’t recall ever running into problems, except perhaps when talking about labeling actual, exact, bit-for-bit drive storage space. Which is a scam, anyway. ๐Ÿ‘ฟ

But the next time you want to scold your friendly neighborhood Linux blogger, you can critique the writer’s integrity with numfmt. Another of the coreutils gems, you can get almost any proper formatting for a number in as simple a command as this:

kmandla@6m47421: ~$ numfmt --to=iec-i 64738

Or …

kmandla@6m47421: ~$ numfmt --to=iec 64738

Or …

kmandla@6m47421: ~$ numfmt --to=si 64738

And so forth, and so on. numfmt will also convert back from abbreviated formats, in such as this:

kmandla@6m47421: ~$ numfmt --from=si 65K

kmandla@6m47421: ~$ numfmt --from=iec 65K

kmandla@6m47421: ~$ numfmt --from=iec-i 65Ki

A little boring, but useful when I need to convert 59.75Gi back into a full string of numbers. …

kmandla@6m47421: ~$ numfmt --from=iec-i 59.75Gi

Remember this, the next time you need to partition a drive with fdisk. It might just save you a trip to Google. ๐Ÿ˜‰

P.S.: For those who really need to know … my rationale on deviating from pure AP Style on MB and MHz and so forth, is that the words are spelled out in full as “megabyte” and “megahertz.” We don’t write “megaByte” or “megaHertz,” or for that matter, split the words as “mega byte” or “mega Hertz.” Since the abbreviations “MB” and “MHz” are deviations from other abbreviations like “km” for kilometer and “kHz” for kilohertz, my mind says “Mb” and “Mhz” aren’t polluting any rules on uppercase and lowercase as they should appear in print. It seems these are determined on a case-by-case basis of what looks right. Of course, you could say that about a lot of things in the AP Stylebook. …

nl: Line numbering, in a variety of ways

nl, out of coreutils again, looks like a fairly simple program.


Given the proper flags though, nl suddenly becomes a wild and crazy guy.


Like a lot of things hiding in coreutils, what looks simple has a lot of very cool options. And it’s clear that nl is capable of handling much more complex arrangements. Watch for options for headers and footers, logical pages and so forth. Most of those things … I don’t even know what they are. ๐Ÿ˜

I can attest to nl‘s usefulness; I’ve used it in the past to add sequence numbers to lists, and to number lines from (of all places) within vim.

And considering the acrobatics it might take to do the same thing without nl, it is definitely a keeper.

seq: Count up, count down

A quick note before we get into seq today: If you left a comment in the past 18 hours or so but don’t see it by now, it might have gotten lost in a spam avalanche.

Someone out there in the world must have turned up the dial on the spam machine, because I had more than 120 spam comments between noon today and early yesterday evening. For reference, I usually see 10 or 12 in a day.

Usually WordPress.com — in spite of all my complaints — does a decent job of filtering out the winners from the losers, but sometimes people get lost in the fracas. If for some reason your comment got mixed in with the spam, I’m sorry, but it’s likely gone forever.

And just FYI: If you include a URL in your comment, it’s more likely to be flagged as dubious by the automated system. Sometimes I can pluck a comment out while it’s circling the drain, but this time there were too many to scan through. My apologies.

Anyways. … seq is up to bat today, and this won’t take long. seq doesn’t do much other than count, by increment, between a stop and a start number. Sounds simple enough.


The fun in seq is getting it to pad its output with leading zeros, which pleases people like me who want their numbered files to line up vertically down the screen. ๐Ÿ™„ And as you can see, you can set a delimiter for seq, which comes in handy at times.

It does pad things a little oddly at times — for example, that 00.0 in the screenshot above. And if you pad your numbers while counting in reverse (yes, you can do that), you’ll find that seq pads 0 as 00, and so forth. I should also mention that seq‘s last output doesn’t carry a separator. That means if you do something funky like this:

kmandla@6m47421: ~$ seq -w -s' '$(shuf -n1 /usr/share/dict/cracklib-small)$'\n' 1 1 10

You’ll see that every line but the last carries a random word. Just so you’re aware. ๐Ÿ˜‰ Things like that are a little unusual but not deal-breakers. Not like join was. ๐Ÿ˜

That’s about all I need to say about seq. It comes in very handy at times, which is probably why it’s part of coreutils. ๐Ÿ˜‰

primes: Ready for primes time!

Just when you thought the masterminds of the ages, the brainiacs behind bsd-games, couldn’t come up with anything more ingenious, along comes primes to blow your mind.


Delightful! Innovative! A product like this hasn’t been seen since Photoshop 1.8a! ๐Ÿ™„

Prime number generation is probably not a huge mathematical drag on your machine, but it is interesting that, according to the man page, primes can only work up to 4,294,967,295.

Beyond that, and you’re back to pencil and paper. ๐Ÿ˜ˆ

Oh, one more thing I like about primes: It has only one bug. And you can check the man page to see what it is. ๐Ÿ˜‰

num-utils: This and that, for numbers

Most of the tools I run across in this silly little adventure are intended for text manipulation. Something that manhandles numbers is … well, unusual.

Enter num-utils.


num-utils comes with an array of tools, mostly involving basic math functions that might otherwise be a bit cumbersome.

For example, there’s random, which — as you might imagine — generates random numbers, given a range.

random can also generate numbers on a particular interval, through decimal ranges or within certain bounds. Not terrifically flashy, but without it, the task could be a little more arduous.

average — again as you might imagine — calculates the average out of a string of numbers. It can also show a median or mode, if you ask nicely.

There are some more esoteric tools. interval — as you might not imagine — calculates the difference between numbers in sequence. So between the numbers 100 and 50 in a sequence, interval would return -50. Unusual.

The home page for num-utils is exceedingly sparse, and the README file suggests everything in the package is in a beta stage.

I hold no grudges against beta software, but that file is stamped 2003. ๐Ÿ˜ฏ

So if you’re waiting for a stable version of num-utils so you can arithmetize your checkbook, I advise being proactive. ๐Ÿ˜•

I should also mention that “beta” is probably accurate, since I did get one or two errors when I used some of the tools, most notably range.

I should also mention that the names given to the tools might run you into conflicts with software in other packages. The title “random” for example is something that appears in bsd-games, unless I’m mistaken. And “normalize” too — there’s a normalize tool of its own right, as I’ve mentioned here.

I see that Debian sidesteps that issue by prefixing the tools with “num”, which is probably a good idea. Archers might have to whack things into place, to keep everyone happy.

Other than that, it’s good to see numbers get the same love as their text counterparts. ๐Ÿ˜‰

mcookie: Mmm, cookies!

No, not really. mcookie will not spit a cookie out of your CD tray. Nice thought though.


mcookie does, however, spit out a random hex string of a predetermined length — which in and of itself might not enthuse you.

But we’ve seen some script-fu in the past that has had clever and practical application, and mcookie could conceivably substitute for that.

And considering that it’s part of the venerable util-linux array, it’s 99 and 44/100 percent likely to be present in your distro by default, predictable in its behavior, and maintained by people in the know.

So let’s review: Ubiquitous, reliable, up-to-date. That has all the makings for a good program.

Want to put it to use, beyond “generating a 128-bit random hexadecimal number for use with the X authority system?” Here’s a weak little idea:

let value=$(echo 0x$(mcookie | head -c2)) && echo $value

It’s a thumbsucker, but it spits out a random decimal value converted from the first two hex digits of mcookie‘s output. Nothing earth-shattering there, but hopefully shows a little of mcookie’s versatility. Mmm, cookies. :mrgreen: