Command line

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 or a string that is passed as an argument. It's commonly used in shell scripts and batch files to output status messages to the screen or a file.

While echo isn't a Git-specific command, it's frequently used in shell scripts and command-line interactions related to Git workflows to display information, construct commands, or manipulate files.

The name "echo" may seem like an odd choice for a command that outputs text. It doesn't have anything to do with sound or acoustics. The name comes from early computing history, where "echo" was used to describe a machine sending back a copy of what was sent to it (just 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

The echo command is commonly used to put a piece of text into a file. You can 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 any existing content. Here's an easy way to remember the difference:

  • >: 1 arrow = keep 1 thing = keep mine
  • >>: 2 arrows = keep 2 things = keep yours and mine

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