15 Practical Examples of ‘echo’ command in Linux

If You Appreciate What We Do Here On TecMint, You Should Consider:

  1. Stay Connected to: Twitter | Facebook | Google Plus
  2. Subscribe to our email updates: Sign Up Now
  3. Use our Linode referral link if you plan to buy VPS (it starts at only $10/month).
  4. Support us via PayPal donate - Make a Donation
  5. Support us by purchasing our premium books in PDF format.
  6. Support us by taking our online Linux courses

We are thankful for your never ending support.

Receive Your Free Complimentary eBook NOW! -

Download Free Linux eBooks

Advanced Bash-Scripting Guide
Linux Bible
A Newbie's Getting Started Guide to Linux
Introduction to Linux - A Hands on Guide

You may also like...

24 Responses

  1. Mohit Kumar says:

    Great list of echo usage. I was going through a particular example where the need is to reformat linux date into human readable date.

    Like: echo $(date +%Y-%m%d\ %H:%M:%S).

    My question is what are the all types of formatting one can do using echo. for example : Can i make particular word or letter in bold? or any other commonly used formatting.

    • Ravi Saive says:

      @Mohit,

      The command ‘echo’ only used to display a line of text, no any formatting its support..

  2. Dave Williams says:

    I am trying the ‘for do’ loop below and experimenting with the echo options. When I submit the script as follows:

    ./forDoLoop.sh peter pan flies

    the text ‘peter pan flies’ doesn’t stay on the screen, it briefly displays the text but then disappears. Please can you tell me what I am doing wrong in the loop below.

    for do loop
    ————–
    for TOKEN in $*
    do
    echo -n $TOKEN
    done

  3. Sravanthi says:

    Hi All ,
    I am beginner to Linux Environment. My problem is, i want to append same text to a file multiple times in single command. How to do it.which command i have to use:
    For Single append i am using

    echo “Hello world” >> testfile.txt (for 1 time)
    cat testfile.txt

    if i want to append 10 times that same Hello world , need to write
    echo “Hello world” >> testfile.txt 10 times? or any other possibilities please.

    i want out put like below:

    Hello world
    Hello world
    Hello world
    Hello world
    Hello world

    like 10 times

    • Ravi Saive says:

      @Sravanthi,

      Instead of using echo, why not use printf command to repeat a string or text multiple times to a file shown in the below example.

      # printf 'HelloWorld\n%.0s' {1..5} >> ravi.txt
      # cat ravi.txt 
      HelloWorld
      HelloWorld
      HelloWorld
      HelloWorld
      HelloWorld
      

Got something to say? Join the discussion.

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

Join Over 150K+ Linux Users
  1. 100,756
  2. 5,113
  3. 36,418

Enter your email to get latest Linux Howto's