Command line tools

echo

echo: print a string of text.

The echo command is a built-in command in various operating systems (Unix, Linux, macOS, and Windows) used to display a line of text/string that is passed as an argument. It is commonly used in shell scripts and batch files to output status text to the screen or a file.

While echo is not a Git-specific command, it is frequently used in shell scripts and command-line interactions related to Git workflows for displaying information, constructing commands, or manipulating files.

The name "echo" might seem a bit odd for a command that outputs text. It doesn't really have anything to do with sound or acoustics. The name comes from early computing history, where the term "echo" was used to describe the action of a machine sending back a copy of what was sent to it (like an echo in real life). In this context, the echo command sends back (to the screen or a file) the text that you give it.

Redirecting output

You can pipe (a fancy word for redirect) the output of echo to a file using the > or >> operators. The > operator overwrites the file if it already exists, while >> appends the output to the end of the file, preserving its existing content. I use the following mnemonic to remember the difference between them:

  • >: Hey, rewrite everything, leaving just the one thing I provided;
  • >>: There could already be something, I don't mind having two things, just add mine to the end.

Examples

Display a simple message:

echo "Hello, World!"
Result:
Hello, World!

Write the output to a new file, overwriting it if it exists:

echo "This is a new file." > file.txt
File: file.txt
Hello, World!

Append the output to an existing file:

echo "This is appended text." >> file.txt
File: file.txt
Hello, World!
This is appended text.
© 2024-2025 GitByBit.All rights reserved.

Hi! I'm Alex, creator of GitByBit.

And this is Gitopedia—a reference that summarizes knowledge in my Git course.

Gitopedia is designed to be a personal knowledge base. When you progress through the main Git course in VS Code, you unlock all of these topics, one by one, bit by bit. This gives you time to digest the information and gradually build the mental model of Git. Here's an example of how it works:

Learning directly in VS Code lets you practice Git exactly as you would in real life, doing real jobs, writing real code. In addition, the course has access to your actual terminal, so it can point out mistakes, suggest workarounds, etc.

The course is FREE, there are no Ads or other bullshit. There are optional premium add-ons you can purchase, mainly to support my work (regrettably, I have to eat every day), but that's totally up to you.

Learn Git in VS Code