echo command is built in command in Linux, that prints text/string passed to this command as an argument on the terminal as an output. In other words, you can say “echo is a command that will display any text that you ask it to display” or “echo command used to display a string provided by the user”.

In this tutorial, you will learn about echo command in Linux and uses of echo command with examples.

Load WordPress Sites in as fast as 37ms!

Uses of echo command

  • Echo is frequently used in code that is written as shell scripts.
  • It is also used to display text/strings or command results as messages.

Syntax of echo command

syntax for echo command is:

echo [option] [string]

Options available with echo.

    1. -n: Do not output the trailing newline
    2. -e: Enable interpretation of backslash escapes
    3. -E: Disable interpretation of backslash escapes (default)
        • \\ : Backslash
        • \a: Alert (BEL)
        • \b: Backspace
        • \c: Produce no further output
        • \e: Escape
        • \f: Form feed
        • \n: New line
        • \r: Carriage return
        • \t: Horizontal tab
        • \v: Vertical tab
        • \0NNN: Byte with octal value NNN (1 to 3 digits)
        • \xHH: Byte with hexadecimal value HH (1 to 2 digits)

echo help

To get help related to echo and display all options available for echo command use the command /bin/echo --help. Simply using echo --help will display –help message.

Load WordPress Sites in as fast as 37ms!
 echo --help

echo help

/bin/echo --help

bin echo help
To get version information for echo use the command /bin/echo --version. Simply using echo --version will display –version message.

Load WordPress Sites in as fast as 37ms!
echo --version
/bin/echo --version

bin echo version
Using echo | Examples of echo command

1. echo command without any option displays exactly the same string as it is provided by the user.

echo "Welcome To Programbr Tutorial"

echo command in Linux
2. By default, the echo command’s output adds new line in output, such that the output is displayed as a single continuous line. If you wish not to add any new line, use -n option with echo. The syntax for not add any trailing newline is:

echo -n "[string]"
echo -n "Welcome To Programbr Tutorial"

echo -n command in Linux

Load WordPress Sites in as fast as 37ms!

Enable interpretation of backslash escapes |Using escape characters

Using the -e option allows you to use escape characters. With escape characters, you can display your text as output in a different manner of your choice.

3. Using sequence \b (backspace) with echo,  will remove all the spaces in between the text.

Load WordPress Sites in as fast as 37ms!
echo -e "Welcome \bTo \bProgrambr \bTutorial"

echo -e b command in Linux
4. Use the sequence \a (alert) with echo, to have a sound alert

echo -e "\aWelcome To Programbr Tutorial"

echo -e a command in Linux
5. Use the sequence \t (horizontal tab) with echo, to have horizontal tab spaces.

echo -e "Welcome \tTo \tProgrambr \tTutorial"

echo -e t command in Linux

Load WordPress Sites in as fast as 37ms!

6. Use the sequence \n (new line) with echo, to text to span into multiple new lines.

echo -e "Welcome \nTo \nProgrambr \nTutorial"

echo -e n command in Linux

7. Use the sequence \v (vertical tab) with echo, to have vertical tab spaces.

echo -e "Welcome \vTo \vProgrambr \vTutorial"

echo -e v command in Linux

8. Use sequence \c (produce no further output) with echo, to omit the portion of text after the additional parameter and suppress the trailing new line.

echo -e "Welocme \cTo programbr Tutorial"

Here echo -e with -/c sequence only printing Welocme and omitted the portion of text To programbr Tutorial and also suppress the trailing new line.

echo -e c command in Linux

9. Use sequence \r (carriage return) with echo, omit the portion of text prior to the additional parameter.

echo -e "Welcome \rTo Programbr Tutorial"

Here echo with \r sequence only printing To Programbr Tutorial and omitted the portion of text Welcome.

echo -e r command in Linux
10. It is similar to ls command. It prints all the files and folders of pwd (present working directory)

echo *

echo star command in Linux

 

A
adduser | addgroup | alias | anacron | apt | aptitude | arp | at | atq | atrm | awk
B
basename | banner | batch | bc | bg | bzip
C
cat | cal | cd | chgrp | chown | cksum | chmod | clear | cmp | comm | cp
D
date | dd | df | diff | dir | dmidecode | du
E
echo | eject | env | exit | expr
F
factor | find | free
G
grep | groups | gunzip | gzip
H
head | history | hostname | hostnamectl | htop | hwclock | hwinfo
I
id | ifconfig | ionice | iostat | ip | iptables | iw | iwlist
J
K
kill | kmod
L
last | less | ln | locate | login | lp | ls | lshw | lscpu | lsof | lsusb
M
man | mdsum | mkdir | more| mv
N
nano | nc | neofetch | netcat | netstat | nice | nmap | nproc
O
openssl
P
passwd | pidof | ping | pr | ps | pwd | pstree
Q
R
rdiff-backup | reboot | rename | rm | rmdir | rnmod
S
scp | shred | shutdown | sleep | sort | split | ssh | stat | su | sudo | sum
T
tac | tail | talk | tar | tee | time | tree | top | touch | tr
U
unalias | uname | uniq | unzip | uptime | users
V
vim | vi
W
w | wall | watch | wc | wget | whatis | whereis | which | who | whoami
X
xargs
Y
yes | youtube-dl
Z
zcmp | zdiff | zip | zz

Sharing is Caring
Load WordPress Sites in as fast as 37ms!
Scroll to Top