June 14, 2026 · by Meegrow Labs

How to Save Command Output to a File in the Terminal

You run a command, the answer flashes on the screen for a second, and then it’s gone. No copy, no paste, no way to get it back. Frustrating, right? The good news is that you can catch that output and keep it forever.

This lesson shows you how to save command output to a file in the terminal using one small symbol. It’s a tiny trick, but you’ll reach for it again and again once you know it.

To save command output to a file, add the greater-than sign (>) followed by a filename after your command. For example, echo hi > note.txt sends the word “hi” into a file called note.txt instead of printing it to your screen.

What does the greater-than sign actually do?

Normally, when a command prints something, that text goes straight to your screen. The moment your terminal moves on, that text is gone.

The greater-than sign (>) changes where the output goes. Instead of the screen, the words land inside a file. Think of it like “Save As”, but from the keyboard.

This is called redirection. You are redirecting the output away from the screen and into a file of your choosing.

How do I save command output to a file?

Let’s break the command apart piece by piece so nothing feels like magic.

echo hi > note.txt
  • echo hi just prints the word “hi”. That’s the output.
  • The > sign catches that output before it reaches the screen.
  • note.txt is the file where the words land.

So nothing shows up on your screen this time. It all gets saved into the file instead. That’s the whole idea.

How do I check that it worked?

Open your file back up and look inside. You already learned the command for this in an earlier lesson on looking inside files with the Zero to AI Hero course.

cat note.txt

You should see this:

hi

The word “hi” was saved, even though it never appeared on your screen the first time. You caught it and kept it.

Why does this matter?

Because output usually vanishes. A command runs, the answer flickers past, and you lose it. With the greater-than sign, you keep it for as long as you want.

This becomes useful in real work all the time. You might save a list of files, a report, or the result of a long command so you can read it later or share it. When you start working with AI tools like Claude Code later in the course, saving output to a file is a habit you’ll use constantly.

Try it right now

Don’t just read this. Open a terminal and type these two lines, pressing Enter after each:

echo hi > note.txt
cat note.txt

If you see hi printed out, you just saved your first command output to a file. Well done.

One small warning: the > sign replaces whatever was already in the file. If note.txt had old text, it gets wiped and replaced. In the next lesson, you’ll learn how to add to a file instead of overwriting it, so nothing gets lost.

Key takeaways

  • By default, command output goes to your screen and then disappears.
  • The greater-than sign (>) redirects that output into a file instead.
  • The pattern is simple: command > filename, for example echo hi > note.txt.
  • Use cat note.txt to read the file and confirm your output was saved.
  • > overwrites the file completely. To add to it without erasing, you’ll use a different symbol in the next lesson.
  • Want to learn the terminal step by step? Start the free Zero to AI Hero course.

🚀 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