Hello everyone, I am Liang Xu. When using Linux, we sometimes need to do some calculations, then we may need to use a calculator. In the Linux command line, there are many calculator tools. These command line calculators allow us to perform scientific calculations, financial calculations or some simple calculations. Of course, we can also use these commands in Shell scripts to perform more complex mathematical operations. Here we mainly introduce 5 command line calculators:
1. How to perform calculations using bc in Linux bc has a standard math library available in the command line options. If required, bc will define the standard math library before processing any files. bc will process the code of each file listed in the command in the order in which it is listed. By default, bc is installed in all Linux distributions. If bc is not available in your system, you can install it yourself by following the command below: For Fedora system, use DNF command to install
For Debian/Ubantu systems, use APT-GET or APT command to install
For Arch Linux based systems, use Pacman command to install
For RHEL/CentOS systems, use the YUM command to install
For openSUSE Leap system, use Zypper command to install
How to use bc command We can use the bc command to perform various calculations such as + - * / ^ % directly in the terminal $ bc bc 1.07.1 Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006, 2008, 2012-2017 Free Software Foundation, Inc. This is free software with ABSOLUTELY NO WARRANTY. For details type `warranty'. 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 Use $ bc -l bc 1.07.1 Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006, 2008, 2012-2017 Free Software Foundation, Inc. This is free software with ABSOLUTELY NO WARRANTY. For details type `warranty'. 3/5 .6000000000000000000 quit 2. How to use calc in Linux If you need to install the calc command, you can refer to the bc command installation method above. How to use the calc command We can use calc to perform various types of calculations interactively in the terminal. $ calc C-style arbitrary precision calculator (version 2.12.7.1) Calc is open software. For license details type: help copyright [Type "exit" to exit, or "help" for help.] ; 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 Of course, you can also use it in non-interactive mode:
3. How to use expr for calculations in Linux expr is part of the core tools library, so we don't need to install it. We can use the following commands to perform basic calculations: $ expr 2 + 3 6 $ expr 6 - 2 4 $ expr 3 * 4 12 $ expr 15 / 3 5 But be sure to note that the numbers and symbols need to be separated by spaces, otherwise the command will not recognize the expression you write: $ expr 2+3 2+3 $ expr 2*3 2*3 4. How to use gcalccmd to perform calculations in Linux Use the gcalccmd command to calculate gcalccmd also has an interactive interface, and the calculation formulas are written in the same way as other calculators. $ gcalccmd > 5+1 6 > 5-1 4 > 5*2 10 > 10/2 5 > sqrt(16) 4 > 3/5 0.6 > quit 5. How to use qalc for calculations in Linux Qalculate's features include a large customizable function library, unit calculations and conversions, symbolic calculations (including integrals and equations), arbitrary precision, uncertainty propagation, interval arithmetic, plotting, and a user-friendly interface (GTK+ and CLI). For Fedora system, use DNF command to install
For Debian/Ubantu systems, use APT-GET or APT command to install
For Arch Linux based systems, use Pacman command to install
For RHEL/CentOS systems, use the YUM command to install
For openSUSE Leap system, use Zypper command to install
Use the qalc command to calculate $ qalc > 5+1 5 + 1 = 6 > ans*2 ans * 2 = 12 > ans-2 ans - 2 = 10 > 1 USD to INR It has been 36 day(s) since the exchange rates last were updated. Do you wish to update the exchange rates now? error: Failed to download exchange rates from coinbase.com: Resolving timed out after 15000 milliseconds. 1 * dollar = approx. INR 69.638581 > 10 USD to INR 10 * dollar = approx. INR 696.38581 > quit 6. How to use Shell commands for calculations In fact, under the Shell command line, we can directly use commands such as echo and awk to perform calculations, which is very convenient. $ echo $((5+5)) 10 $ cat data | awk '{sum+=$1} END {print "Sum = ", sum}' # Calculate the sum of the data in the data file Summarize This concludes this article about 5 calculator commands in Linux command line. For more information about calculator commands in Linux command line, please search previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Reasons why MySQL 8.0 statistics are inaccurate
>>: Antd+vue realizes the idea of dynamic verification of circular attribute form
I see many novice students doing front-end develop...
0. Prepare relevant tables for the following test...
How to solve the timeout problem when pip is used...
The installation and configuration method of MySQ...
Table of contents 1. Basics 2. Nodes, trees, and ...
The method of using CSS style to vertically cente...
I am planning to organize the company's inter...
Preface: Partitioning is a table design pattern. ...
Table of contents Preface 1. Error log 2. Binary ...
A long time ago, I summarized a blog post titled ...
Phenomenon: Change the div into a circle, ellipse...
What we need to pay attention to is that the char...
Networks usage tutorial Official website docker-c...
When doing database statistics, you often need to...
#mysql -uroot -p Enter password mysql> show fu...