Linux Echo Command and Usage Examples

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/linux-echo-command-usage-examples/
PINTEREST
PINTEREST
INSTAGRAM

Echo is popular command comes with all of the Linux distributions. Echo is provided by bash and C shells. Echo simple outputs given values to the console or terminal.

Man Echo

To get more detailed help and echo official documentation use following command

Man Echo

Man Echo

Syntax

Echo command provides two type of syntax like below.

OR

Display Text

Simple and most common usage of echo command is just printing specified text to the standard output like below.

Display Text

Display Text

Print Variables

Other popular usage form is printing shell variables like below.

Print Variables

Print Variables

Remove Spaces While Printing

There is -e option which will remove all spaces by using back spaces defined with \b while printing text

Remove Spaces While Printing

Remove Spaces While Printing

Bash Echo New Line

Another useful usage is adding \n control character which will print new line.

New Line

New Line

Tab

While printing some text to the standard output tabs can be placed in to this text by using \t

Tab

Tab

Vertical Tab

Vertical tab will provide new line and align the output text like below.

Vertical Tab

Vertical Tab

Carriage Return

Carriage return will delete previous part of the text and only print after last carriage return with \r

Carriage Return

Carriage Return

Backspace

Backspace control character will delete single character to the backward with \b in the text.

Backspace

Backspace

Omit New Line

Normally after printing text to the standard output new line is provided to make things more clear. But this new line can be prevented with option -n 

Omit New Line

Omit New Line

Alert

Alert can provided to the shell subsystem with \a . This is very useful to make shell scripts and application more interactive

Alert

Alert

This option will not effect to the output of the text.

Print All Files and Folders

Echo command can work with bash features easily. To easily and simply print all files and folders of the current directory following command can be used.

Print All Files and Folders

Print All Files and Folders

Print specific Extension Files

While printing files and folders specific extensions can be used to filter output. For example we want to print to the standard output only c source files with extension .c 

Print specific Extension Files

Print specific Extension Files

Write Into File

Without opening any text editor some text can be written to a file. The file must not be preexist. If file is all ready exist all content is deleted and given text is written to the text file.

Write Into File

Write Into File

Create Empty File

Empty file can be create by providing empty string definition and redirecting this to a file.

Create Empty File

Create Empty File

Add To The File

Last example about the echo command is adding more text to the existing file. Adding operation will no delete existing text in the file.

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/linux-echo-command-usage-examples/
PINTEREST
PINTEREST
INSTAGRAM

Leave a Reply

Your email address will not be published.

Enjoy this blog? Please spread the word :)