June 14, 2026 · by Meegrow Labs

How to Append to a File in Terminal (>> vs >)

You saved some text into a file. Then you ran the same command again to add one more line. But when you opened the file, everything you wrote earlier was gone. That single arrow you used did not add your text. It quietly erased the file first.

This is one of the most common surprises for beginners. The good news: learning how to append to a file in terminal takes one extra character, and it keeps your old work safe.

To append to a file in the terminal, use two greater-than signs (>>) instead of one. A single > overwrites the file and wipes everything inside it, while >> adds your new text to the bottom and keeps the old lines intact.

Why does a single arrow erase my file?

The single greater-than sign (>) means “send this output into a fresh file.” Every time you run it, the terminal empties the file and starts over.

So if you run this twice, only the last line survives:

echo "first line" > note.txt
echo "second line" > note.txt

Open note.txt and you will see only second line. The first line is gone. Nobody warned you, and that is exactly why losing work hurts.

What is the difference between > and >>?

Think of a grocery list. You do not rewrite the whole list every time you want to add one item. You simply write the new item at the bottom, and the old items stay where they are.

  • > (one arrow) overwrites the file. Old content is erased.
  • >> (two arrows) appends to the file. New text joins the bottom, old text stays safe.

That is the whole fix. One more arrow, and nothing gets erased.

How do I append to a file in the terminal?

Let us break the command apart so every piece makes sense:

echo "more" >> note.txt
  • echo "more" prints the text more. That is your new line.
  • >> takes that line and adds it to the bottom of the file.
  • note.txt keeps everything it already had.

So the file does not get reset. It just grows by one line. Old lines stay, the new one joins them.

Can I try this right now?

Yes, and you should. Open your terminal and run these lines one by one:

echo "first line" > note.txt
echo "more" >> note.txt
cat note.txt

The cat command prints the file’s contents. You should now see both lines:

first line
more

Both lines are there. The first one was not erased. That is the safe way to build a file up over time, whether you are keeping notes, logging results, or saving steps as you learn.

Why does this matter for working with AI?

As you move toward tools like Claude Code and AI agents, you will save logs, notes, and instructions into files all the time. Knowing when text is added versus erased means you never lose your work by accident. Small habits like this are what let you truly command the terminal instead of fearing it.

If you are just starting out, you can follow every step in order with the free Zero to AI Hero course. Each short lesson builds on the last, so the terminal stops feeling scary and starts feeling like home.

Key takeaways

  • To append to a file in terminal, use two greater-than signs (>>).
  • A single > overwrites the file and erases everything inside it.
  • >> adds your new text to the bottom and keeps the old lines safe.
  • Test it with echo "more" >> note.txt, then run cat note.txt to see both lines.
  • Next up: copying a file’s contents in one line.

Want to keep the streak going? Continue with the next lesson in the free Zero to AI Hero course and learn it step by step.


🚀 Take the full free course: Zero to AI Hero — learn to build with AI from scratch. New lessons daily, in Hindi & English.

Meegrow Labs

We help India go from zero to AI hero — learn to use & build with AI from scratch, in Hindi & English. Start the free course →

Want to actually learn this?

151 free 2-minute lessons — from "what's a file?" to building with AI.

▶ Start the free course