Cantech Knowledge Base

Your Go-To Hosting Resource

How to Use the echo Command in Linux?

Searching for ways to print a message or display variables in Linux?

Do not worry! It can be done easily using the most powerful echo command in Linux.

Here, in this tutorial, we will guide you in using the echo command in Linux, why it is helpful and the usage of echo commands. Let’s go through them!

What is echo Command in Linux?

In simple terms, the echo command in Linux is used to print text, variables or characters for the standard output that can be a terminal. Such an in-built Linux command is widely used in shell scripts or terminal commands to display outputs, debug code or system status. The general syntax for the echo command is as follows:

echo [options] [text...]

Here, the [options] signifies varied options for modifying the echo command.
[text….] represents the text or variables to be displayed.

Why Do You Use the echo Command in Linux?

Here are a few reasons you require using the echo command in Linux!

  • To showcase text or status in scripts.
  • Used for debugging purposes.
  • To communicate information with a command-line environment.
  • Used for creating user-friendly shell scripts.
  • To create complex pipelines and one-liner commands via other tools.
  • Display the output of variables on a terminal.

Basic Uses of the echo Command

Let’s explore some of the uses of the echo commands!

1. Display a Message using the echo command.

echo "Hello, World!"

Output: Hello, World!

2. Display the output of variables on a terminal using the echo command.

name="Cantech" && echo "Welcome to $name"

Output: Welcome to Cantech

3. Showcase text message with the system date.

echo "Today is" $(date)

Output: Today is Tue May 6 03:09:30 PM UTC 2025

4. To show output as special characters.

echo -e "Line 1 \nLine 2 \nLine 3"

Output:
Line 1
Line 2
Line 3

5. Display text in a single line.

echo -n "Hello, "
echo "eCommerce enthusiasts!"

Output: Thisisourwebsite

echo -e "This \bis \bour \bwebsite"

Output: Thisisourwebsite

7. To add tabs between the words.

echo -e "This \tis \tmy \twebsite"

Output: This is my website

Useful Options With echo Command

Option Description
-n Prevents a newline at the end of the output
-e Enables interpretation of escape characters like \n, \t
-E Disables escape characters (default behavior)

Escape Sequences to Use with -e

Using echo -e allows you to include special characters in your output. Let’s have a look!

Escape Sequence Function
\n New line
\t Tab space
\\ Backslash
\” Double quote
\a Alert (system beep)
\b Backspace
\r Carriage return
\c Suppress remaining output

Final Thoughts

Using echo command in Linux is simple and widely used in printing simple messages and scripting complicated automation logs. It is the foremost step for beginners to have detailed knowledge of terminal output and powerful shell scripts.

Frequently Asked Questions

1. Why do you use the echo command in Linux?

The echo command in Linux is used to show text or variable values on the terminal. Additionally, it is widely used in command-line environments to offer the standard output.

2. How do you print a message in Linux?

To print a message in the terminal, you need to use echo.

echo "Hello, World!"

Output: Hello, World!

3. How do I echo a command path in Linux?

You can use which command within the echo to show the path of the command.

echo (which python3)

Output: /usr/bin/python3

4. What is the use of the -n flag?

The -n flag is used to print text on a similar line without adding a new line.

5. Explain the basic difference between echo and printf in Linux.

The echo command is a basic and simple command to display the output. Whereas, the printf command is used for advanced formatting while handling numbers or aligned text.

May 23, 2025