Master Linux Command‑Line Calculators: bc, calc, expr, gcalccmd & qalc
This guide introduces five Linux command‑line calculators—bc, calc, expr, gcalccmd, and qalc—explaining how to install them on various distributions, use their interactive and non‑interactive modes, and perform common arithmetic, scientific, and unit‑conversion tasks.
Linux users often need to perform calculations directly from the terminal. This article presents five command‑line calculators— bc, calc, expr, gcalccmd, and qalc —covering their installation on major distributions and basic usage examples.
1. Using bc
bcis an arbitrary‑precision calculator with a C‑like syntax. It is pre‑installed on most Linux systems; otherwise install it with:
Fedora: $ sudo dnf install bc Debian/Ubuntu: $ sudo apt install bc Arch: $ sudo pacman -S bc RHEL/CentOS: $ sudo yum install bc openSUSE Leap: $ sudo zypper install bc Basic arithmetic works directly:
<code>$ bc bc 1.07.1 1+2 3 10-5 5 2*5 10 10/2 5 13/5 2 (2+4)*5-5 25 2^3 8 8%3 2 quit</code>
Use the -l option to load the standard math library for floating‑point results, e.g., $ bc -l yields 3/5 → .60000000000000000000.
2. Using calc
calcprovides arbitrary‑precision calculations with a simple interactive prompt. Install it using the same commands as bc. Example session:
<code>$ calc C-style arbitrary precision calculator (version 2.12.7.1) ; 5+1 6 ; 5-1 4 ; 5*2 10 ; 10/2 5 ; 13/5 2.6 ; 13%5 3 ; 2^4 16 ; 9^0.5 3 ; quit</code>
Non‑interactive use: $ calc 3/5 → 0.6.
3. Using expr
expris part of the coreutils package, so no installation is required. It evaluates integer expressions; spaces are required between operands and operators.
$ expr 2 + 3
5
$ expr 6 - 2
4
$ expr 3 \* 4
12
$ expr 15 / 3
5Incorrect spacing (e.g., expr 2+3) results in the literal string being echoed.
4. Using gcalccmd
gcalccmdis the console version of GNOME Calculator, typically pre‑installed on GNOME desktops. It supports standard arithmetic and functions like sqrt():
<code>$ gcalccmd > 5+1 6 > sqrt(16) 4 > 3/5 0.6 > quit</code>
5. Using qalc (Qalculate)
Qalculate is a powerful cross‑platform calculator offering unit conversion, currency conversion, arbitrary precision, and symbolic math. Install the library package:
Fedora: $ sudo dnf install libqalculate Debian/Ubuntu: $ sudo apt install libqalculate Arch: $ sudo pacman -S libqalculate RHEL/CentOS: $ sudo yum install libqalculate openSUSE Leap: $ sudo zypper install libqalculate Example interactive session:
<code>$ qalc > 5+1 5 + 1 = 6 > ans*2 ans * 2 = 12 > 1 USD to INR 1 * dollar = approx. INR 69.638581 > quit</code>
6. Shell built‑ins for simple calculations
For quick arithmetic, Bash arithmetic expansion can be used:
$ echo $((5+5))
10Data processing can be done with awk:
$ cat data | awk '{sum+=$1} END {print "Sum = ", sum}'This collection equips Linux users with a range of tools—from basic integer math to advanced scientific and unit calculations—usable directly from the command line.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
