How to perform calculation in Linux using bc Command?

As a Linux administrator you may use the command line calculator many times in a day for some purpose.

I had used this especially when LVM creation using the PE values.

There are many commands available for this purpose and I’m going to list most used commands in this article.

These command line calculators will allow us to perform all kind of actions such as scientific, financial, or even simple calculation.

Also, we can use these commands in shell scripts for complex math.

In this article, I’m listing the top five command line calculator commands.

bc: An arbitrary precision calculator language
calc: arbitrary precision calculator
expr: evaluate expressions
gcalccmd: gnome-calculator – a desktop calculator
Linux Shell:
How to perform calculation in Linux using bc Command?
bs stands for Basic Calculator. bc is a language that supports arbitrary precision numbers with interactive execution of statements. There are some similarities in the syntax to the C programming language.

A standard math library is available by command line option. If requested, the math library is defined before processing any files. bc starts by processing code from all the files listed on the command line in the order listed.

After all files have been processed, bc reads from the standard input. All code is executed as it is read.

By default bc command has installed in all the Linux system. If not, use the following procedure to install it.

For Fedora system, use DNF Command to install bc.

$ sudo dnf install bc
For Debian/Ubuntu systems, use APT-GET Command or APT Command to install bc.

$ sudo apt install bc
For Arch Linux based systems, use Pacman Command to install bc.

$ sudo pacman -S bc
For RHEL/CentOS systems, use YUM Command to install bc.

$ sudo yum install bc
For openSUSE Leap system, use Zypper Command to install bc.

$ sudo zypper install bc

Leave a Reply

Your email address will not be published.