In this article we are going to shows how to use Echo command in Linux Terminal. If you want to learn about Echo command in Linux with Examples then this post is ideal for you.
The echo is a command line utility that is used to display the passed arguments to the standard output. In the Linux, it is a very common and frequently used command.
Echo is a built in command that is basically used in shell scripts and batch files to display message and output status text to the screen or a file.
echo Command in Linux
In the Linux, the basic syntax of the echo command is show as below:
echo [-neE] [ARGUMENTS]-
-noption is used, the trailing newline is suppressed. - -e option enables the interpretation of the following backslash-escaped characters :
\\– Shows a backslash character.\a– Alert (BEL)\b– its is used to displays a backspace character.\c– Suppress any further output\e– It displays an escape character.\f– Displays a form feed character.\n– it is used to create new line from where it is used\r– Show a carriage return.\t– Display a horizontal tab.\v– It will display a vertical tab.
-Eoption disables the interpretation of the escape characters. By default it is disabled.
How to use echo Command in Linux
Examples of echo command
Display a text/string on standard output:
$ echo Hello, studiesonlineOutput
Hello, studiesonlineUse \b option to removes all the spaces in between the text:
echo -e "studiesonline \bfor \byou"Output
studiesonlineforyouUse \n option to creates new line from where it is used in command:
$ echo -e "studiesonline \nfor \nyou"Output
studiesonline
for
youTo create horizontal tab spaces, use \t option :
$ echo -e "studiesonline \tfor \tyou"Output
studiesonline for youUse \v option to create vertical tab spaces:
echo -e "studiesonline \vfor \vyouOutput
studiesonline
for
youDisplay a line of text/string containing a double quote
$ echo 'Hello "studiesonline"'or
$ echo "Hello \"studiesonline\""Output
Hello "studiesonline"Display a line of text/string containing a single quote
$ echo "hello I'm feeling well"or
$ echo $'hello I\'m feeling well'Output
hello I'm feeling wellDisplay a text/string containing special characters
Use -e option to enables the interpretation of backslash escapes.
$ echo -e "The way to get started is to quit talking and begin doing.\n\t- Walt Disney"Output
The way to get started is to quit talking and begin doing.
- Walt DisneyPattern matching characters
$ echo The Text files are: *.txtThe above command show the all .txt files in your current working directory.
Display the output to a file
Use the >, >> operators with the echo command to display the output to the file instead of displaying on the screen.
echo -e 'The way to get started is to quit talking and begin doing.\n\t- Walt Disney' >> /tmp/filename.txtAbove command create a file filename.txt if it doesn’t exist in your system. If you use the > operator then it will be overwrite and if you use the >> operator then it will append the output to the given file.
Display variables using echo command
$ echo $USEROutput
studiesonline$USER is a shell variable that is contains your username.
Display output of a command using echo command:
$ echo "Date is: $(date +%D)"Output
Date is: 01/29/20That’s all.
If you face any error and issue in above steps , please use comment box below to report.
If our tutorials helped you, please consider buying us a coffee. We appreciate your support!
Thank you for your support.



