DEV Community

Cover image for Linux: echo
Aakriti
Aakriti

Posted on

Linux: echo

echo

  • Write output to standard input
Option Usage Example
-n Do not appened to a new line. The terminal curser will be in the same line as the output instead of being in a new line by default . [aaakriti@aakriti ~]$ echo -n "Harry Potter"
Harry Potter[aaakriti@aakriti ~]$ write your next command here
-e enables interpretation of \ backslash escapes Will be used in combination of \ options
-E Opposite of -e. Explicitly supress interpretation of backslash escapes Will be used in combination of \ options
\a Alert through Volume. Make sure your volume is high. It will ring a ting on an output [aaakriti@aakriti ~]$ echo -e "\aHarry Potter"
Harry Potter
\b Backspace, removes all spaces between the texts [aaakriti@aakriti ~]$ echo -e "Harry \bPotter"
HarryPotter
\b It removes the n no. of character occurring before the \b used. Depending on the no. pf times used [aaakriti@aakriti ~]$ echo -e "Harry\b\bPotter"
HarPotter
\c Suppress further output. Will not output whatever is written after \c [aaakriti@aakriti ~]$ echo -e "Harry \c Potter is my favourite"
Harry
\e Escape character. Omits the just next single character succeeding to \e [aaakriti@aakriti ~]$ echo -e "\eHarry"
arry
\n Creates a new line [aaakriti@aakriti ~]$ echo -e "Harry \nPotter \nis \nmy \nfavourite"
Harry
Potter
is
my
favourite
\r Carriage return. Will not return whatever is return before \r. opposite of \c [aaakriti@aakriti ~]$ echo -e "Harry \r Potter is my favourite"
Potter is my favourite
\t Horizontal tabs. Use tabs as spaces. Example
\v Vertical tab space. In a slanting manner Example

Other tricks

Option Usage
echo * Lists all files and folders
echo $x echo value of a variable
\n + \t new line + tab
\n + \v new line + verticle tab
echo "Test" > testpage.log will add contents to a file
1. echo 'Harry "Potter"'
2. echo "Harry \"Potter\""
Harry "Potter"
echo $(command) Output of the command
echo ~ home folder
echo {1..5} 1 2 3 4 5
echo $((50*2)) 100
1. echo -e "\033[1;37mWHITE"
2. echo -e "\033[0;34mBLUE"
Display in respective colors

Fun tricks

  • Make someone get lost in dark black world of linux: echo -e "\033[0;30mBLACK" {"mode":"full","isActive":false}

Top comments (2)

Collapse
 
thefluxapex profile image
Ian Pride

A better title might be:

Shell: Echo

or maybe even more fitting:

GNU: Echo

As the echo command is a GNU Core utility and is used in any environment/operating system that uses the GNU Core Utilities, not just Linux.

Also, since this is for novice people you might want to explain ways that they can get this info themselves locally on their machines so they don't have to depend on a web browser; a couple of examples:

The manual pages (MAN):

man echo
Enter fullscreen mode Exit fullscreen mode

and (sometimes) -h, --help

echo --help
Enter fullscreen mode Exit fullscreen mode
Collapse
 
aakriti_1012 profile image
Aakriti • Edited

Well actually, you are right and thanks for the feedback.
What I am trying to create is a friendly man page with examples to work as a to-go place. The reason it is tabular is because we often have to go deep into an article skimming things to find what we are looking for. To solve this problem and save time, I created a table. Everything is in front of your eyes, skim and choose what you are looking for.