The echo command in Linux writes its arguments to standard output, usually followed by a newline. On Ubuntu you almost always use the shell builtin (type echo → echo is a shell builtin). GNU coreutils also ships /bin/echo for cases where no shell is involved. Official note from man echo: your shell’s echo may differ; printf is preferred when portability or option-like strings matter.
type -a echo # echo is a shell builtin # echo is /bin/echo help echo # bash builtin help man echo # documents /bin/echo (coreutils)
If you already know your goal, jump to: -n/-e, write to a file, newline quoting, or echo vs printf. To view files afterward, use cat or tail.

For a broader Ubuntu terminal quick reference, see the Linux commands cheat sheet.
Basic Syntax
echo [OPTION]... [STRING]...
echo Hello echo Hello World echo "Hello World"
Default behavior: print the strings separated by spaces, then a trailing newline.
Useful Options (-n, -e, -E)
GNU /bin/echo (and bash’s builtin with similar flags) supports:
| Option | Meaning |
|---|---|
-n | Do not print the trailing newline |
-e | Enable backslash escapes (\n, \t, …) |
-E | Disable escapes (default for /bin/echo) |
echo -n "Prompt: " # cursor stays on same line echo -e "Line1\nLine2" # two lines echo -e "Col1\tCol2" # tab between columns echo -e "Path: C:\\\\temp" # show a backslash
Common escapes with -e (from the Ubuntu man page):
| Escape | Meaning |
|---|---|
\n | Newline |
\t | Tab |
\\ | Backslash |
\a | Bell |
\b | Backspace |
\r | Carriage return |
\c | Stop output here |
\xHH | Hex byte |
\0NNN | Octal byte |
Bash builtin details: help echo. External binary: man echo.
Variables and Quoting
name=Ubuntu echo $name echo "$name" # safer with spaces/glob chars echo "User: $USER home=$HOME" echo 'Literally $USER' # single quotes: no expansion
Unquoted $var still undergoes word-splitting and globbing—prefer "$var" in scripts.
Write (or Append) to a File
echo "first line" > notes.txt # overwrite echo "second line" >> notes.txt # append
Root-owned files: sudo echo … > /etc/file fails—the shell opens the file as you. Use:
echo "options ..." | sudo tee /etc/modprobe.d/local.conf >/dev/null echo "line" | sudo tee -a /etc/file >/dev/null
(Same Ask Ubuntu pattern as other sudo + redirection issues—see the sudo command guide.)
Newlines and Command Substitution (Classic Gotcha)
# File has multiple lines, but this prints one line: echo $(cat input.txt) # hello world ! # Keep newlines — quote the substitution: echo "$(cat input.txt)"
Ask Ubuntu explanation: without quotes, word-splitting turns newlines into spaces. Also, $(…) strips trailing newlines—use cat/printf carefully when byte-exact output matters.
Why /bin/echo Exists
Ask Ubuntu: the builtin is for speed; /bin/echo exists because tools like find -exec, xargs, .desktop Exec=, and sudo echo run programs without a shell:
find src -name 'abc*' -type f -exec echo mv -nv {} dest/ \;
type -a echo
/bin/echo --version # coreutils version stringPrefer printf over depending on differences between bash echo and /bin/echo.
Echo vs Printf
| Use | Prefer |
|---|---|
| Quick interactive print | echo |
Scripts, formats, leading - text | printf |
| Portable escape handling | printf |
# echo can mis-handle strings that look like options: echo -n # may mean “no newline,” not print “-n” # printf is explicit: printf '%s\n' -n printf 'Name: %s\n' "$USER" printf 'Line1\nLine2\n'
The coreutils man page explicitly recommends printf(1) as the preferred alternative.
Colors and Escape Sequences (Optional)
echo -e "\033[1;32mOK\033[0m" # or printf '\033[1;31mError\033[0m\n'
Works in terminals that understand ANSI codes; avoid relying on color in logs meant for files.
Common Mistakes
| Mistake | Fix |
|---|---|
Lost newlines with echo $(cat f) | echo "$(cat f)" or just cat f |
sudo echo x > /root/f permission denied | echo x | sudo tee /root/f |
Expecting -e everywhere | Behavior varies by shell; use printf in scripts |
| Unquoted variables | Use "$var" |
| Need exact bytes / formats | Prefer printf |
Quick Cheat Sheet
echo hello echo -n "no newline" echo -e "a\tb\nc" echo "$VAR" echo "line" > file echo "line" >> file echo x | sudo tee /path >/dev/null printf '%s\n' "$VAR" # safer in scripts type -a echo
From Shell Output to Shareable Documents
echo is a fast way to print values, append small lines, or build simple shell output. But when that output becomes a note, checklist, or attachment for someone else, plain terminal text is only the first step.
WPS Office for Linux gives Ubuntu a cleaner desktop handoff: Writer for formatted notes, Spreadsheet for structured values, and PDF for fixed output.

| What you need next | What WPS gives you |
|---|---|
| Turn shell output into a readable final document | Strong .docx / .xlsx / .pptx layout fidelity when files move between Linux, Windows, and macOS |
| One place for notes, sheets, slides, and PDFs | Free core suite: Writer, Spreadsheet, Presentation, plus PDF view/edit/convert tools |
| A familiar desktop UI for switchers | Ribbon-style apps with a lighter footprint than many heavy suites |
| A trusted install path | Official DEB (Ubuntu/Debian/Mint) and RPM packages from the vendor |
Use the official WPS Office for Linux download page, then install the local package with sudo apt install ./wps-office_VERSION_amd64.deb. Keep echo for shell text; use WPS when the result should open as a polished file instead of another terminal line.
FAQ
What does the echo command do in Linux?
It prints its arguments to standard output, normally ending with a newline.
What is echo -e?
It enables interpretation of backslash escapes like \n and \t (GNU echo / typical bash builtin).
What is echo -n?
It suppresses the trailing newline—useful for prompts.
Builtin vs /bin/echo?
Interactive bash uses the builtin; /bin/echo is for non-shell callers (find -exec, xargs, etc.).
When should I use printf instead?
In scripts, for reliable formatting, and when the string might look like an option.
Where is the official documentation?
Run help echo (bash), man echo (/bin/echo), and man printf, or see the Ubuntu echo(1) man page.




