So far commands have printed to the screen. Now send that output somewhere useful.
The arrow
echo Hello from the terminal > hello.txt
Nothing appears on screen. That is the point: the > caught the output that echo would have printed and wrote it into hello.txt instead.
Check it:
cat hello.txt
Hello from the terminal
You just created a file with content in it, without ever opening an editor.
Note
This is called redirection, and it is not an echo feature — it works with any command. ls > files.txt saves a folder listing. grep ERROR log.txt > errors.txt saves just the error lines. Anything that prints can be redirected.
Quick check
You run `ls > files.txt` and see no output. What happened?
One arrow replaces. Two arrows add.
> does not add to a file. It replaces it, completely, with no warning and no confirmation:
echo first > notes.txt
echo second > notes.txt
cat notes.txt
second
first is gone. There is no undo.
Use >> to append instead:
echo first > notes.txt
echo second >> notes.txt
cat notes.txt
first
second
Important
This is the single most expensive typo in the terminal. > on a file that already matters wipes it instantly and silently. Before you point a at an existing file, take the half-second to check whether you meant >>.
Quick check
You want to add a line to a file that already has content. Which do you use?
A useful habit
When you are not certain what a command will produce, run it without the redirect first and look at the output. Then run it again with the redirect.
grep ERROR server.log
grep ERROR server.log > errors.txt
Costs you one extra command, saves you writing garbage into a file you then have to clean up.
Quick check
Why run a command once without the redirect before adding one?
Try it
Build a small file in two steps:
echo Hello from the terminal > hello.txt— create it with one line.echo Second line >> hello.txt— append a second.cat hello.txt— read both lines back.
Then try echo Oops > hello.txt followed by cat hello.txt, and watch both lines vanish. Better to learn that here than on something you care about.