When studying computer science, cryptography, or advanced mathematics, calculating the prime factors of a large number is a frequent requirement. Prime factorization is the process of breaking down a complex integer into a set of basic prime numbers that, when multiplied together, equal the original integer. While you could write a Python script or use a calculator to figure this out, Linux includes a tiny, incredibly fast utility built specifically for this mathematical task: the factor command.
How to Find Prime Factors
The factor utility is a standard component of the GNU Core Utilities, meaning it is pre-installed on virtually every Linux distribution in existence.
To use it, simply type the command followed by the integer you want to analyze.
factor 12
The output will instantly display the original number followed by a colon, and then a space-separated list of its prime factors.
12: 2 2 3
This tells you that 2 × 2 × 3 equals 12, and both 2 and 3 are prime numbers.
Analyzing Extremely Large Numbers
The true power of the factor command is its mathematical efficiency. It can handle incredibly large integers far beyond what a standard desktop calculator can process without crashing or freezing.
For example, you can ask it to factorize a massive number like 8,675,309:
factor 8675309
The terminal will instantly return:
8675309: 8675309
Because there is only one number listed after the colon, the factor command has just mathematically proven that 8,675,309 is, itself, a prime number.
If you factorize a massive non-prime number, it will break it down instantly:
factor 9999999999
Output:
9999999999: 3 3 11 41 271 9091
Interactive Mode
If you are working through a long list of math homework problems, typing the word factor over and over again is inefficient. You can launch the utility in interactive mode by simply typing factor and pressing Enter with no arguments.
factor
The command will sit waiting for your input. Every time you type a number and press Enter, it will immediately output the factors on the next line and wait for your next number. You can type as many numbers as you want in rapid succession. When you are finished, press Ctrl + C to exit the utility and return to your standard bash prompt.