Write things into a file
Redirect output with >
⏱ Est. ~5 min
01 · Read
You can do more than print to the screen — you can redirect output into a file. The > symbol writes output into a file, overwriting whatever was there before.
💡 Picture thisLike wiping a whiteboard clean and writing something new on it. Everything that was there is gone.
Key points
- > redirects output into a file
- It replaces the entire file contents
- If the file doesn't exist, it gets created
02 · Terminal exercise
Create a file with content: use echo together with > to redirect the output into a file.
(This section is interactive — please enable JavaScript.)
03 · Terminal exercise
Let's verify it worked.
(This section is interactive — please enable JavaScript.)
04 · Terminal exercise
Now let's overwrite the file.
(This section is interactive — please enable JavaScript.)
05 · Terminal exercise
Read the file again to see what just happened.
(This section is interactive — please enable JavaScript.)
06 · Quiz
What happens if you use > to redirect output into a file that already has contents?
- The whole file gets replaced with the new content
- The new content is added to the end
- Nothing happens — the file is protected
- It makes a backup first
Other lessons in this chapter
⚠ The full interactive experience needs JavaScript. Please enable it and reload.
※ This is an independent Traditional Chinese teaching project — not an official Anthropic product. Claude™ is a trademark of Anthropic, PBC.