gives primefactors of 20
factor 20
gives prime factors of all the numbers
factor 30 50 60
Output:
36: 2 2 3 3
(36 is factored as 2 × 2 × 3 × 3)
factor 36
Output:
37: 37
(Since 37 is a prime number, the output is the number itself.)
factor 37
Output:
56: 2 2 2 7
75: 3 5 5
98: 2 7 7
(This calculates prime factors for multiple numbers in one command.)
factor 56 75 98
Output:
123456: 2 2 2 2 2 2 3 643
(Shows how a large number can be broken down into its prime factors.)
factor 123456
Output:
987654321: 3 3 17 17 379721
(The factor command can handle large numbers efficiently.)
factor 987654321
Output:
10: 2 5
11: 11
12: 2 2 3
13: 13
14: 2 7
15: 3 5
16: 2 2 2 2
17: 17
18: 2 3 3
19: 19
20: 2 2 5
(This factors numbers from 10 to 20.)
for i in {10..20}; do factor $i; done
Then view the file:
cat factors.txt
factor 100 200 300 > factors.txt
(Reads numbers from numbers.txt and factors them.)
cat numbers.txt | xargs factor
(Save as factor_script.sh, make it executable with chmod +x factor_script.sh, and run it.)
#!/bin/bash
echo "Enter a number:"
read num
factor $num
Output (for 97):
Prime
factor 97 | awk '{if (NF==2) print "Prime"; else print "Not Prime"}'
Displays the prime factors of a number.
factor 12