Looking through the GNU Coreutils, I spotted the factor command, that I had never noticed before.

Reading the man page:

Print the prime factors of each specified integer NUMBER. If none are specified on the command line, read them from standard input.

Is there a practical use for factor, or is it just a demonstration / toy package?

7 Answers 7


Wikipedia, "Factor (Unix)" with an interesting take:

factor first appeared on 5th edition Research Unix in 1974, as a "user maintained" utility (section 6 of the manual). In the 7th edition in 1979, it was moved into the main "commands" section of the manual (section 1). From there, the factor utility was copied to all other variants of Unix, including commercial Unixes and BSD. In some variants of Unix, it is classified as a "game" more than a serious utility, and therefore documented in section 6.

So it would seem that some user(s) liked to play around with prime factors and wrote factor - and once it existed, there probably was no good reason not to include it as a command in subsequent Unix versions. So the "practical uses" of factor may depend on what you consider practical - if you are into prime number theory, it is probably a great tool/game/whatever.

  • one could think of 1337 reasons Jun 20, 2021 at 0:55

I know that in at least one case, for me factor was helpful in the analysis of a large data file of unknown format.

If you suspect a file has fixed length records, the prime factors of the file's length provide a starting point from which to determine the actual record length.


Most tools are useful to someone. Here's a question from someone who wants to use factor to help divide up a large file into optimally-sized chunks.

Find a "moderately large" divisor of a given number?


It will tell you what prime numbers can be multiplied together to get the number you've specified:

e.g 20 = 2 * 2 * 5


> factor 20

You get 20: 2 2 5 as output

If the number was a prime, e.g 19, you will get a 19 only.

  • Thanks, I kind of got this from the man page. I was more curious why you would want to do this in a shell script, or similar. How often do people actually need prime roots? I updated the question to be clearer. Sep 5, 2012 at 2:24

I consider this to be the primary practical use:

alias primetime='watch -t -n 1 "factor \$(date +%s)"'
  • Noob to bash, could you explain how to use this? I naively just tried running it in ato.pxeger and got no output.
    – DrQuarius
    Sep 17, 2023 at 0:30
  • It defines an alias called primetime. An alias is a way of defining a new command, usually as a shorthand for some longer more complex command that you need to execute frequently. For example, if you frequently use ls -l, then you might define an alias for it: alias ll="ls -l". To use it, simply type the new command; in this case, type primetime. You can read more about aliases in the Bash manual page, which can be read online by typing man bash.
    – db48x
    Sep 17, 2023 at 2:17
  • Actually, I just tried ato.pxeger and it doesn’t give you an interactive bash session, so this is useless there. If you have an OSX or Linux computer, open a terminal and type it in there.
    – db48x
    Sep 17, 2023 at 2:17

This may be an utility descended from the early days of UNIX, before scientific calculators were cheap, small, and plentiful.

It may have served to allow the developers of the original UNIX to show that the whole thing could do something useful and that it should keep receiving funding.

  • 1
    It demonstrates none of the features of Unix though as it's purely computational. Dec 10, 2012 at 20:13
  • 2
    In the early days of Unix, the roff typesetter was developed to satisfy the funding requirements of Unix.
    – Kusalananda
    Oct 25, 2018 at 15:54

Prime numbers play a large role in cryptography, although I know very little about it, I could fathom that they may find it useful for identifying large primes and the like

  • 6
    factor is limited to numbers that fit into an unsigned integer. Best case, that's 64 bits (≤ 18,446,744,073,709,551,615)—but the smallest number you'd reasonably use in e.g., RSA is 2048 bits. IOW, That's much larger than factor can handle. In fact its so much larger, that writing out how many times larger exceeds the maximum length of a comment. It's almost 600 digits long (it's 2¹⁹⁸⁴ if you want to calculate it yourself with e.g., bc)
    – derobert
    Dec 10, 2012 at 20:06
  • So not useful today, but maybe 35 years ago? Was cryptography using keys with that high of entropy then? Just thought it might be a possible reason it exists. Dec 10, 2012 at 21:25
  • No. If factor can factor the number (without chugging for many, many years on it), then it is useless for cryptography. Also, I bet factor uses a relatively slow algorithm...
    – derobert
    Dec 10, 2012 at 21:30
  • 1
    Told ya I know very little about cryptography. haha Dec 10, 2012 at 21:46
  • 4
    @derobert at least the version on my machine (8.25) uses libgmp and can factor very large numbers: 184467440737095516150000000000001: 19 37 227601536870423 1152893543912729 Apr 26, 2016 at 19:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .