dc command in Linux with examples Last Updated : 22 Oct, 2024 Comments Improve Suggest changes 4 Likes Like Report The dc command is a versatile calculator found in Linux systems, operating using reverse Polish notation (RPN). This command allows users to perform arithmetic calculations and manipulate a stack, making it ideal for complex mathematical tasks directly from the command line.SyntaxThe basic syntax for using the dc command is as follows:dc [OPTION] [file ...]Examples of dc CommandExample 1: Basic AdditionTo illustrate how dc works, consider this simple example:echo "5 3 + p" | dc Output: 8In this case, the command adds 5 and 3, then prints the result.Example 2: Basic Arithmetic OperationsExample 3: Changing Output RadixNote: In second example, the output changes because we changed the output-radix. Key Options Commonly Used with the CommandThe dc command includes several options and operations for stack manipulation. Below is an overview of some essential commands:CommandOperationpPrints the value on the top of the stack and ends the statement with a newline.nPrints the value on the top of the stack and ends the line with a null statement.fPrints the entire stack, without any alteration.PPops the value from the top of the stack.cClear the stack.dDuplicates the top value and push it into the main stack.rReverses the order of top two elements in the stack.ZPops the value from the stack, calculate the number of digits in it and pushes that number.XPops the value from the stack, calculate the number of fraction digits in it and pushes that number.zPushes the stack length into the stack.iPops the value from the stack and uses it as input radix.oPops the value from the stack and uses it as output radix.kPops the values from the stack and uses it to set precision.IPushes the value of input radix into the stack.OPushes the value of output radix into the stackKPushes the precision value into the stack.expression: This command is used to evaluate a particular expression.file: This command is used to evaluate the contents of the file.help: This command displays help information.version: This command is used to display version information.ConclusionThe dc command provides a powerful means to perform arithmetic operations directly from the terminal. Its use of reverse Polish notation may take some getting used to, but its ability to handle arbitrary precision makes it a valuable tool for both simple calculations and more complex mathematical tasks. Create Quiz Comment D DrRoot_ Follow 4 Improve D DrRoot_ Follow 4 Improve Article Tags : Technical Scripter Linux-Unix Technical Scripter 2018 linux-command Linux-Shell-Commands +1 More Explore Linux/Unix Tutorial 5 min read Getting Started with LinuxWhat is Linux Operating System 8 min read LINUX Full Form - Lovable Intellect Not Using XP 2 min read Difference between Linux and Windows 7 min read What are Linux Distributions ? 8 min read Difference between Unix and Linux 5 min read Installation with LinuxHow to Install Arch Linux in VirtualBox? 7 min read Fedora Linux Operating System 12 min read How to install Ubuntu on VirtualBox? 6 min read How to Install Linux Mint? 3 min read How to Install Kali Linux on Windows? 2 min read How to Install Linux on Windows PowerShell Subsystem? 2 min read How to Find openSUSE Linux Version? 2 min read How to Install CentOS 2 min read Linux CommandsLinux Commands 15+ min read Essential Unix Commands 7 min read Find Command in Linux with Examples 7 min read Linux File SystemLinux File System 12 min read Linux File Hierarchy Structure 5 min read Linux Directory Structure 6 min read Linux KernelLinux Kernel 4 min read Kernel in Operating System 3 min read How Linux Kernel Boots? 11 min read Difference between Operating System and Kernel 3 min read Linux Kernel Module Programming: Hello World Program 7 min read Linux Loadable Kernel Module 7 min read Loadable Kernel Module - Linux Device Driver Development 4 min read Linux Networking ToolsNetwork configuration and troubleshooting commands in Linux 5 min read How to configure network interfaces in CentOS? 5 min read Command-Line Tools and Utilities For Network Management in Linux 8 min read Linux - Network Monitoring Tools 4 min read Linux ProcessProcesses in Linux/Unix 5 min read How to Manage Process in Linux 4 min read Getting System and Process Information Using C Programming and Shell in Linux 2 min read Process states and Transitions in a UNIX Process 4 min read Linux FirewallLINUX Firewall 7 min read iptables command in Linux with Examples 7 min read How to Configure your Linux Firewall - 3 Methods 12 min read Shell Scripting & Bash ScriptingIntroduction to Linux Shell and Shell Scripting 7 min read What is Terminal, Console, Shell and Kernel? 5 min read How to Create a Shell Script in linux 7 min read Shell Scripting - Different types of Variables 4 min read Bash Scripting - Introduction to Bash and Bash Scripting 12 min read Bash Script - Define Bash Variables and its types 12 min read Shell Scripting - Shell Variables 6 min read Bash Script - Difference between Bash Script and Shell Script 4 min read Shell Scripting - Difference between Korn Shell and Bash shell 3 min read Shell Scripting - Interactive and Non-Interactive Shell 3 min read Shell Script to Show the Difference Between echo â$SHELLâ and echo â$SHELLâ 4 min read Like