Linux Commands Examples

A great documentation place for Linux commands


display a line of text


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

add an example, a script, a trick and tips

: email address (won't be displayed)
: name

Step 2

Thanks for this example ! - It will be moderated and published shortly.

Feel free to post other examples
Oops ! There is a tiny cockup. A damn 404 cockup. Please contact the loosy team who maintains and develops this wonderful site by clicking in the mighty feedback button on the side of the page. Say what happened. Thanks!


echo echo

equivalent "echo on" for linux?

Use bash -v.

This is the script:

#!/bin/bash -v

echo "Hello, World" | sed 's|Hello|Goodbye|'

echo "Done."

This is the output:

#!/bin/bash -v

echo "Hello, World" | sed 's|Hello|Goodbye|'
Goodbye, World

echo "Done."

Unfortunately, there is no special marker like PS4 for printing expanded commands. You could combine both though to quickly identify commands:

#!/bin/bash -vx

echo "Hello, World" | sed 's|Hello|Goodbye|'
+ echo 'Hello, World'
+ sed 's|Hello|Goodbye|'
Goodbye, World

echo "Done."
+ echo Done.

Can a string be inserted at a specific line in a file from the CLI?

Here's some perl solutions:

perl -p -i -e 'print "Hey\n" if /Hi/'  filename


perl -p -i -e 'print "Hey\n" if $. == 4'  filename


perl -n -i -e 'print; print "Hey\n" if /Hello/' filename

Use xargs to send requests to the same server in parallel with netcat

Use echo -n or you will get 5 connections instead four, one of them with no data. If in the server this is not checked, maybe it is causing your problem.

echo -n A,B,C,D | xargs -d, -I{} -P 4 -n 1 echo {} | nc localhost 7000

Moreover, using a netcat as listening server, it appears to work right:

zhen@sydow:~$ nc -l 7000

And also it seems to be parallel, I see out-of-order echo.


How to escape newline in the commandline?

printf "%s\n%s\n%s\n" "Line 1", "Line 2", "Line 3"

In a for loop, how do I echo only the current file on a single(updating) line instead of EVERY file which will produce a list?

Just change the echo line to this:

echo -ne "\r  * $file > $newf                         "

The spaces on the end clear old output from the line.


How to get GNU-Screen Command in Linux to echo locally

My mistake, I had an open screen session and didn't know how to reconnect to it, so I forced a new session by sudo screen and that session was extremely messed up (corrupt characters) and didn't echo 90% of the characters. I was able to reconnect to that session and all was well.


How does `echo` work in this context?: `externalip() { curl; echo; }`

Why does it echo the response body of the previous curl command?

A classic loaded question.

It doesn't do any such thing. The curl command outputs an IP address without a trailing newline. The echo command supplies the newline. It's that simple.


echo "$(curl -s"

is more straightforward than

curl ; echo

is a matter of taste to some extent. It's worth noting, however, that $() is not available in the Bourne (not to be confused with the Bourne Again) shell nor in the C shells, whereas pretty much all shells can execute two plain commands in sequence separated by a semi-colon. That even includes csh and fish. ☺


space at the end of variable is killed on output

As ever so often, the answer lies in quoting.

echo -n $TEST > text

This will get expanded to:

echo -n test  > text

Note the two spaces after test. The only arguments echo sees are -n and test. Nothing else. The space gets lost here. To keep it, you need to double-quote $TEST:

echo -n "$TEST" > text

See also: Quotes and escaping on the Bash Hackers wiki.


How to input text in a file in a specific line?

sed -i 's/command=/&sudo /' file

explanation: examining the file line-by-line, replace the text "command=" with "command=sudo ". The & in the replacement string will be whatever is matched from the left-hand side.


Echo the STRING(s) to standard output.


do not output the trailing newline


enable interpretation of backslash escapes


disable interpretation of backslash escapes (default)


display this help and exit


output version information and exit

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




alert (BEL)




produce no further output




form feed


new line


carriage return


horizontal tab


vertical tab


byte with octal value NNN (1 to 3 digits)


byte with hexadecimal value HH (1 to 2 digits)

NOTE: your shell may have its own version of echo, which usually supersedes the version described here. Please refer to your shell’s documentation for details about the options it supports.


Copyright © 2012 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <>.
This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.

reporting bugs

Report echo bugs to bug-coreutils[:at:]gnu[:dot:]org
GNU coreutils home page: <>
General help using GNU software: <>
Report echo translation bugs to <>

see also

The full documentation for echo is maintained as a Texinfo manual. If the info and echo programs are properly installed at your site, the command

info coreutils 'echo invocation'

should give you access to the complete manual.


Written by Brian Fox and Chet Ramey.

How can this site be more helpful to YOU ?

give  feedback