How to Use the Linux Terminal as a Calculator

Linux Terminal Calculators Featured

Do you prefer the simplicity of the Linux terminal over a fancy GUI? If you need to quickly do some math, you don’t have to use a calculator app. You can perform your calculations using the terminal, using tools that you’ll (probably) have installed already.

Let’s run through how you can use the Linux terminal as a calculator, no matter your distro.

Calculations with GNU bc

The bc element of GNU bc stands for “basic calculator.” The bc program itself originated on Unix, based in the 1970s. GNU bc is a more modern, enhanced version, one that you should find on your Linux system already.

If you don’t have GNU bc, use the package manager your distro uses to install it – the package is simply called bc. To start it, open your terminal and type bc before hitting Enter. Type quit to exit the program once you’re done.

Linux Terminal Calculators Gnubc

The plus, minus, forward slash, and asterisk symbols are used for calculation. The first two (plus and minus) are straightforward, while the forward slash is used for division and the asterisk for multiplication.

You can also use brackets, variables, arrays, algebraic expressions, etc. Further instructions can be found with the GNU bc manual.

Calculations with Calc

An alternative to bc is calc, another terminal-based tool. Like bc, it’s another old Unix tool which has found continued support on Linux. The installation package is called apcalc on Ubuntu and Debian-based systems but can be found as calc elsewhere.

To open it, simply type calc in a terminal and hit Enter. Like bc, you’ll need to use typical operators. For example, 5 * 5 for five multiplied by five.

Linux Terminal Calculators Calc

When you type a calculation, hit Enter. The answer will appear directly below it. Once you’re done, type quit and hit Enter.

Using Terminal Commands Directly (Echo and Expr)

You don’t necessarily need any additional programs or packages to perform basic math calculations using a Linux terminal. Typical bash shells allow you to perform basic calculations yourself using echo. You might do this if you’re planning on using math as part of bash scripts, for instance.

You can also use expr, a tool which comes with coreutils, found on almost all Linux and Unix-based systems. Expr is useable in bash scripts, as with echo.

To use echo, type echo $((2*2)) where 2*2 is your chosen calculation, into the terminal. Press Enter and the answer to your calculation is then returned to you.

Linux Terminal Calculators Echo

To use expr, type expr followed by your calculation. Again, this can only cope with simple mathematical calculations, so no trigonometry here.

For example, expr 33 \* 2 will multiply 33 by two. The backslash before the asterisk is required for multiplication here but not for other operators.

Linux Terminal Calculators Expr

Echo and expr are useable if you’re looking to perform basic math calculations only. If you need something more advanced, choose another method listed here.

Calculations with Qalc

If you’d prefer something with a few additional features, like currency conversion, Qalc is the tool you’ll need. It’s the terminal cousin of Qalculate, a cross-platform calculator with a GUI.

Use your distribution package manager to install the qalc package. Start it by typing qalc into the terminal and hitting enter.

Linux Terminal Calculators Qalc

It’s the most comprehensive and friendly terminal calculator app for Linux users. It’ll also remember your past calculations, as well as present your answers neatly below.

If you want to perform currency conversion, you’ll need to start qalc and then type exrates to update the exchange rates first.

Math on Linux, Easy as Pi

Math isn’t the easiest thing to master, but you can take away the hassle of quick Linux math calculations using the terminal. Tools like echo and expr, as well as common software like GNU bc, help to make your number crunching simple, easy and quick.

Which Linux calculation tool is easiest for you and which is your favorite? Let us know in the comments below.

Leave a Comment

Yeah! You've decided to leave a comment. That's fantastic! Check out our comment policy here. Let's have a personal and meaningful conversation.