Linux echo command tutorial: echo syntax and echo examples

linux echo command – display a line of text.

Echo command is one of the most commonly used commands and is commonly used in scripting languages ​​to display a line of text/string on a standard output or file.


echo [SHORT-OPTION]... [STRING]...


  • -n
    do not output the trailing newline
  • -e
    enable interpretation of backslash escapes
  • -E
    disable interpretation of backslash escapes (default)
  • –help
    display this help and exit
  • –version
    output version information and exit

If –e is in effect, the following sequences are recognized:

   \\     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)


empty file

➜  ~ echo > test.txt  
➜  ~ echo ""> test.txt 

echo newline or Multi-line, using optino “-e” and “\n”

➜  ~ echo -e "hello! \nylspirit"

append file content using echo

➜  ~ echo "ylspirit" >> test.txt 

echo content to file

➜  ~ echo "hahaha, hello, ylspirit" > test.txt 

print the variable value using echo command – echo $

➜  ~ x=100
➜  ~ echo $x
➜  ~

print all the files/folder using echo command

➜ echo *

print files of a specific kind using echo command

➜ echo *.txt

join strings using echo command

Recommended Posts:

Linux common commands tutorial and use examples
GNU sed syntax and sed examples
Awk tutorial: awk syntax and awk examples
chmod command and chown command usage
iostat syntax and iostat examples
grep command and grep examples
top syntax and top examples

Add a Comment

Your email address will not be published. Required fields are marked *