Writing with Redirection
> sends output to a file.
Every command so far has printed its answer on the screen. But you can send that output somewhere else instead, straight into a file. This is called redirection, and it uses the greater than sign.

- Output goes to the screen
- Or into a file
- Redirection: >
Echo into a file
Echo hello, greater than, greeting dot TXT. Nothing appears on screen this time, because the output went into the file instead. Cat shows the file now holds the word hello. If the file didn't exist, the shell created it.
echo hello > greeting.txt cat greeting.txt hello
Any command can be saved
This works with any command, not just echo. Here we save the list of files in Pictures, and the current date, each into a file. It's an easy way to keep a record of what a command said.
ls Pictures > pictures.txt date > today.txt cat pictures.txt today.txt beach.jpg party.jpg Mon Jan 5 09:00:00 UTC 2026
Careful: it replaces
There's a catch. A single greater than sign replaces the whole file. Here we write goodbye into greeting dot TXT, and hello has vanished. The shell empties the file first, before the command even runs. So be careful not to point it at a file you care about.
echo hello > greeting.txt echo goodbye > greeting.txt cat greeting.txt goodbye
Summary
Greater than sends a command's output into a file, creating it if needed. But it replaces whatever was there. Next, how to add to a file instead.
Key takeaways- cmd > file
- Creates the file
- Replaces the contents