Mission 4 of 5
Writing and Reading File Content
Write a short note, append to it, and confirm the result.
Write text, append text, read files, reverse lines, and save command output.
Mental model
Understand what is happening
> overwrites a file; >> appends to it.
Ctrl+D ends interactive cat input.
tee is useful when you want to see output and save it.
Guided lab
Work through the mission
Write and append
Creates a file and appends another line. Remember: > overwrites.
cd ~/linux-practice
echo 'First line' > journal.txt
echo 'Second line' >> journal.txt
cat journal.txtNumber and reverse lines
Shows numbered lines and reverse order.
cat -n journal.txt
tac journal.txtSave output with tee
Saves a directory listing while also displaying it.
ls -la | tee listing.txt
cat listing.txtCheckpoint
Verify the mission
The saved file contains both the original and appended lines.
Try it yourself
One step without a recipe
Create journal.txt with three lines. Use cat -n and tac to inspect it.
Need a hint?
I've destroyed a config file more times than I'd like to admit by typing `>` when I meant `>>`. Now I pause for half a second before every redirect. That tiny habit has saved me hours of rebuilding files from scratch.
Explain it back
Before you move on
- Which operator appends?
- What does tee do?