• Categories
    Category
    {{ postCtrl.tags }}
    • {{ category.tag_type }}

      • {{tag.tag_name}}
      • View more
  • Categories
    Category
    {{ postCtrl.tags }}
    • {{ category.tag_type }}

      • {{tag.tag_name}}
      • View more
  • News
  • Tutorials
  • Forums
  • Tags
  • Users
Tutorial News Comments FAQ Related Articles

Echo Command in Linux with Examples

{{postValue.id}}

Echo Command in Linux

Echo is a built in command for bash and C shells. It can be used to display a line of text on a standard output or it could able to append into a new file.

Syntax

echo < options> < contents>

To input a line of text and display on standard output

[root@linuxhelp Desktop]# echo Linuxhelp is a master in linux and Opensource
Linuxhelp is a master in linux and Opensource

To declare a variable and echo its value

We will declare a variable of x and assign its value to 10

[root@linuxhelp Desktop]# x=100

Echo its value as follows.

[root@linuxhelp Desktop]# echo The value of varible x = $x
The value of varible x = 100

Note: -e in Linux acts as interpretation of escaped characters that are back slashed.

To remove all the spaces in between

' ' &ndash backspace with backslash interpretor ' -e' is used to remove all the spaces in between.

[root@linuxhelp Desktop]# echo -e " Linuxhelp is a master in linux and Opensource" 
LinuxhelpisamasterinlinuxandOpensource

To create a new line

The option ‘ ‘ &ndash New line with backspace interpreter ‘ -e‘ treats new line from where it is used.

[root@linuxhelp Desktop]# echo -e " Linuxhelp 
is 
a 
master 
in 
linux 
and 
Opensource" 
Linuxhelp
is
a
master
in
linux
and
Opensource


To have horizontal tab spaces

Option ‘ ‘ &ndash horizontal tab with backspace interpreter ‘ -e‘ is sued to have horizontal tab spaces.

[root@linuxhelp Desktop]# echo -e " Linuxhelp 	is 	a 	master 	in 	linux 	and 	Opensource" 
Linuxhelp is a master in linux and Opensource

To have vertical tab spaces

[root@linuxhelp Desktop]# echo -e " vLinuxhelp vis va vmaster vin vlinux vand vOpensource" 

Linuxhelp
is
a
master
in
linux
and
Opensource

To use option new Line ‘ ‘ and horizontal tab ‘ ‘ simultaneously

[root@linuxhelp Desktop]# echo -e " 
	Linuxhelp 
	is 
	a 
	master 
	in 
	linux 
	and 
	Opensource" 

Linuxhelp
is
a
master
in
linux
and
Opensource

To use option new Line ‘ ‘ and vertical tab ‘ v‘ simultaneously

[root@linuxhelp Desktop]# echo -e " 
vLinuxhelp 
vis 
va 
vmaster 
vin 
vlinux 
vand 
vOpensource" 

Linuxhelp

is

a

master

in

linux

and

Opensource

To have specified carriage return in output

Option ‘ ‘ &ndash carriage return with backspace interpreter ‘ -e‘ is used to have specified carriage return in output.

[root@linuxhelp Desktop]# echo -e " Linuxhelp 
is a master in linux and Opensource" 
is a master in linux and Opensource

To continue without emitting new line

Option ‘ c‘ &ndash suppress trailing new line with backspace interpreter ‘ -e‘ is used to continue without emitting new line.

[root@linuxhelp Desktop]# echo -e " Linuxhelp is a master cin linux and Opensource" 
Linuxhelp is a master [root@linuxhelp Desktop]#

To omit echoing trailing new line

-n option is used to omit echoing trailing new line.

[root@linuxhelp Desktop]# echo -n " Linuxhelp is a master in linux and Opensource" 
Linuxhelp is a master in linux and Opensource[root@linuxhelp Desktop]#

To have sound alert

Option ‘ a‘ &ndash alert return with backspace interpreter ‘ -e‘ is used to have sound alert.

[root@linuxhelp Desktop]# echo -e " Linuxhelp is a master in linux aand Opensource" 
Linuxhelp is a master in linux and Opensource

To print all the files/folder using echo command

[root@linuxhelp Desktop]# echo *
111.txt file1.txt file2.txt untitled folder


To print files of a specific kind

You can print all the jpeg file by using the following command.

[root@linuxhelp Desktop]# echo *.jpeg
a1.jpeg a2.jpeg a3.jpeg abc.jpeg b1.jpeg b2.jpeg c1.jpeg

To output to a file and not standard output

The redirect operator can be used with echo to output to a file and not standard output.

[root@linuxhelp Desktop]# echo " Linuxhelp Page"  >  linuxhelppage
[root@linuxhelp Desktop]# cat linuxhelppage
Linuxhelp Page

Tags:
jackson
Author: 

Comments ( 0 )

No comments available

Add a comment
{{postCtrl.cmtErrMsg}}

Frequently asked questions ( 5 )

Q

How to add to last line in echo command

A

echo "hello world" >> file.txt

Q

I print the message using echo command. But, is it possible to view it in green color

A

echo -e "\033[32m hello world"

Q

How to check for a Specific environment variable in linux

A

echo "$variable_Name"

Q

How to use echo command to read and print content of a file

A

echo "$(

Q

How to delete content of a file using echo command

A

echo "" > file_name

Back To Top!
Rank
User
Points

Top Contributers

userNamenaveelansari
135850

Top Contributers

userNameayanbhatti
92510

Top Contributers

userNamehamzaahmed
32150

Top Contributers

1
userNamelinuxhelp
31040

Top Contributers

userNamemuhammadali
24500
Can you help Sebastian ?
How to change non required to required field in SuiteCRM Custom/Default Modules

How to change not required to the required field in SuiteCRM Custom/Default Modules?

Networking
  • Routing
  • trunk
  • Netmask
  • Packet Capture
  • domain
  • HTTP Proxy
Server Setup
  • NFS
  • KVM
  • Memory
  • Sendmail
  • WebDAV
  • LXC
Shell Commands
  • Cloud commander
  • Command line archive tools
  • last command
  • Shell
  • terminal
  • Throttle
Desktop Application
  • Linux app
  • Pithos
  • Retrospect
  • Scribe
  • TortoiseHg
  • 4Images
Monitoring Tool
  • Monit
  • Apache Server Monitoring
  • EtherApe 
  • Arpwatch Tool
  • Auditd
  • Barman
Web Application
  • Nutch
  • Amazon VPC
  • FarmWarDeployer
  • Rukovoditel
  • Mirror site
  • Chef
Contact Us | Terms of Use| Privacy Policy| Disclaimer
© 2025 LinuxHelp.com All rights reserved. Linux™ is the registered trademark of Linus Torvalds. This site is not affiliated with linus torvalds in any way.