
echo Command in Linux with Practical Examples
How to Use the echo Command in Linux (with 5 Practical Tricks You’ll Actually Use)
The echo command in Linux is often the very first command a new user learns. Many beginners start with echo “Hello World!”, see their text printed back, and quickly move on, thinking it’s just a simple utility for displaying strings. It’s the “hello world” of the command line — fundamental, but seemingly basic.
But what is echo in Linux really? Far from just printing text, it’s a versatile tool for debugging, formatting output, automating tasks, and even monitoring system status. Whether you’re a casual user or a sysadmin, mastering the echo command in Linux opens up powerful scripting capabilities and helps you understand how the terminal communicates with the system.
If you’re exploring Linux basics, mastering echo is one of the best ways to get hands-on with shell scripting and output formatting. Let’s dive into how this simple command can actually perform advanced tasks.
What is the echo Command in Linux?
At its core, the echo command displays text or output on the terminal. It takes a string or variable as input and prints it to standard output (stdout).
Syntax:
echo [option] [string]
Example:
echo “Hello, Linux!”
Output:
Hello, Linux!
That’s the simplest form. But once you start combining echo with flags, redirections, and variables, it becomes a multi-purpose tool for automation, debugging, and reporting.
1. It’s a Master of Disguise: Styling and Coloring Your Output
The echo command in Linux can style terminal output using ANSI escape codes, making scripts visually intuitive. With the -e option, escape sequences like 33 allow text formatting, color changes, and background styling. This can help make logs or scripts more readable.
Using the -e Option for Escape Sequences
To enable text styling, you must use the -e option. It tells echo to interpret special escape characters like n (newline), t (tab), or color codes.
Example: Color Coding Text in Terminal
echo -e ' 33[0;30mBLACK'
echo -e ' 33[0;32mGREEN'
echo -e ' 33[1;37mWHITE'
echo -e ' 33[0;34mBLUE'
echo -e ' 33[0;31mRED'
Each number corresponds to a color or text style. For instance:
- 0;30m → Black
- 0;31m → Red
- 1;37m → Bright White
After printing colored text, it’s good practice to reset color formatting using:
echo -e “
