Whether you’re completely new to Linux or have been using a Linux desktop for a long time, there are some commands that may not seem to make sense. This is especially true if you never dive into the command line, which is where much of the true power of Linux and other Unix-like operating systems comes into play.
One of these is the venerable
echo command. At first glance, this may seem like auseless command. Look under the hood, and you’ll find it to be surprisingly useful.
What Does ‘echo’ Do?
Look at the manual entry for
echo, and you won’t find much help. It reads “displays a line of text.” This you could probably already infer from the name of the command.
Basically, what echo does is send arguments to standard outputs along with a handful of basic formatting options. The main reason this command exists is to work inside other scripts, letting you show output to the person running the script.
At a basic level,
echo does exactly what it says it does. Here’s an example:
That will print “Can anybody hear me.” If you just type the command, it literally looks like an echo, which is where the command gets its name. If you add a question mark to the above command, though, you’ll get an error. Type the following:
The resulting text won’t have the quotes around it, but will properly display the question mark. You can also use variables with the
The above command will print 256 to the terminal.
More Advanced Commands
echo command works differently on certain systems. On Linux, for example, there are some options that you won’t find on other Unix-like operating systems. For example, the
-e option allows you to insert characters like
\n for newline or
\t for tabs.
It may look a little confusing at the end, but this will print something similar to the following:
You can also use
\b for backspace. Why you would want to delete a word you just carefully typed out may not make sense, but it does have the occasional use case.
As already explained, the most practical use case for
echo is in scripts you write. You can also use it do some slight cleanup for the output of other scripts. That said, for that use case there are many better tools for the job like
Another great use case for
echo is in slightly modifying configuration files. Just use the standard
> redirect. As an example:
This will append the text to the file “just-a-file.txt.” Run it again and the line will appear twice.
As you’re reading through these examples, you may find yourself wondering why anyone would ever use them. It could even have you second-guessing why anyone would ever want to use Linux instead of Windows or macOS.
Usually, when something about Linux seems strange, it’s because it has its roots in how it was used decades ago. That doesn’t necessarily mean anything bad, though. If you’re not sure about Linux, take a look at our list of reasons you should learn to use Linux.
Our latest tutorials delivered straight to your inbox