You can calculate various mathematical functions in Linux using the bc command or other tools like awk and python. Here are some examples:
Using bc
-
Addition:
echo "5 + 3" | bc -
Subtraction:
echo "10 - 4" | bc -
Multiplication:
echo "7 * 6" | bc -
Division:
echo "scale=2; 10 / 3" | bc -
Exponentiation:
echo "2^3" | bc
Using awk
You can also use awk for calculations:
-
Addition:
echo | awk '{print 5 + 3}' -
Square Root:
echo | awk '{print sqrt(25)}'
Using python
If you have Python installed, you can use it for more complex calculations:
-
Basic Operations:
python -c "print(5 + 3)" -
Square Root:
python -c "import math; print(math.sqrt(25))" -
Exponentiation:
python -c "print(2 ** 3)"
These methods allow you to perform a wide range of mathematical calculations directly from the command line.
