Suggested day 420–30 minutesSafe in practice folder

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.

Outcome: You understand the difference between creating a file and putting content into it.

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

1

Write and append

Safe

Creates a file and appends another line. Remember: > overwrites.

Terminal
cd ~/linux-practice
echo 'First line' > journal.txt
echo 'Second line' >> journal.txt
cat journal.txt
2

Number and reverse lines

Safe

Shows numbered lines and reverse order.

Terminal
cat -n journal.txt
tac journal.txt
3

Save output with tee

Safe

Saves a directory listing while also displaying it.

Terminal
ls -la | tee listing.txt
cat listing.txt

Checkpoint

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?

Shortcuts:Alt + ← previous lessonAlt + → next lessonAlt + H home? focus search