In the next article we are going to take a look at some commands to use the calculator from the terminal from Ubuntu. Many Gnu / Linux users usually need to use the calculator from the terminal several times a day for some purpose, so it is always interesting to know some options.
Today we can find many commands available for this purpose. These calculators for the terminal will allow us perform all kinds of calculations simple, scientific or financial. We will also be able to use these commands in shell scripts for more complex math. Next we are going to see some of the most used.
Commands for using the calculator in the terminal
Bc command
Bc stands for basic calculator. Supports arbitrary precision numbers with interactive execution of statements. It has some similarities in the syntax of the C programming language.
By default, the command bc we will find it installed on all Gnu / Linux systems. If you cannot find it installed on your Debian / Ubuntu system, you can use the following command to install bc by opening a terminal (Ctrl + Alt + T) and typing in it:
sudo apt install bc
Use the bc command
We can use the bc command to perform all kinds of calculations directly from the terminal (Ctrl + Alt + T) by typing in it:
If we use the -l option the standard math library is going to be defined:
bc -l
Calc command
Calc is a simple calculator that allows us to perform all kinds of calculations on the command line. To install it on Debian / Ubuntu systems, we can use the following command in the terminal (Ctrl + Alt + T) to install calc:
sudo apt install apcalc
Use the calc command
We will be able to use the calc command to perform all kinds of calculations directly from the terminal (Ctrl + Alt + T) using the interactive mode, writing:
calc
If we prefer to use the non-interactive mode, you just have to write the command followed by the operation to be performed:
calc 88/22
Expr command
This command will print the value of the operation that accompanies expose on standard output. It is part of coreutils, so we don't need to install it.
Use the expr command
We will use the following format for the basic calculations.
To add:
expr 5 + 5
To subtract:
expr 25 - 4
To divide:
expr 50 / 2
Gcalccmd command
Gnome-calculator is the official calculator for the GNOME desktop environment. Gcalccmd is the console version of the utility Gnome Calculator.
To install this command you just have to open a terminal (Ctrl + Alt + T) and write in it:
sudo apt install gnome-calculator
Use the gcalccmd command
In the following screenshot you can see some examples of use:
gcalccmd
Qalc command
It is an easy-to-use calculator, but it provides the power and versatility They are usually reserved for complicated math packages, as well as useful tools for everyday needs.
Features include a large library of customizable functions, unit calculations and conversions, symbolic calculations (including integrals and equations), arbitrary precision, interval arithmetic, plotting, and an easy-to-use interface (GTK + and CLI).
For Debian / Ubuntu systems, we will be able to use qalc by typing in a terminal (Ctrl + Alt + T) the following command:
sudo apt install qalc
Use the qalc command
In the following screenshot you can see some examples to get a little idea of how to use this calculator:
qalc
It can consult more about qalc on your page GitHub.
Shell commands
We will be able use shell commands like echo, awk, etc. to perform the calculation of operations. For example, to perform an option you just have to type the following in the terminal (Ctrl + Alt + T):
echo $[ 34 * (12 + 27) ]
In this case we will also be able to use variables when performing calculations:
x=5 y=6 echo $[ $x + $y ]
The calculator is undoubtedly one of the most essential tools that we must have in any day-to-day system. For this reason, if you are an administrator or a user who uses the terminal daily, these commands that we have seen above may be useful.
Charlie brow