Mission 4 of 30

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.

35–45 min Week 1 · Terminal basics Ubuntu terminal
Your outcome: You understand the difference between creating a file and putting content into it.
Practice inside ~/linux-practice. Check your setup before you begin. Prerequisite: Creating and Inspecting Files .

What you’ll practice

  • Use echo and cat
  • Understand overwrite vs append
  • Use tee to view and save output

The mental model

  • > overwrites a file; >> appends to it.
  • Ctrl+D ends interactive cat input.
  • tee is useful when you want to see output and save it.

Try it in your terminal

Write and append

Safe in practice folder

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

Run from ~/linux-practice

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

Number and reverse lines

Safe in practice folder

Shows numbered lines and reverse order.

Run from ~/linux-practice

cat -n journal.txt
tac journal.txt

Save output with tee

Safe in practice folder

Saves a directory listing while also displaying it.

Run from ~/linux-practice

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

Put it into practice

  1. Create journal.txt with three lines.
  2. Use cat -n and tac to inspect it.

Check your result

The saved file contains both the original and appended lines.

Common mistakes

  • You append to a file with `>>` for twenty minutes, then accidentally type `>` once. Your file now has one line. I've done this. The fix: when the file matters, copy it first. `cp journal.txt journal.txt.bak` before any redirect.

Check your understanding

Explain these in your own words. If you’re unsure, revisit the examples before moving on.

  1. Which operator appends?
  2. What does tee do?

Your practice, your pace

Loading saved progress…

Discussion

Continue the conversation about this guide. Loading comments connects to GitHub Discussions through giscus.

Open community discussions on GitHub

Check before you copy

This command needs care. Read its context, confirm the target and location, and keep a recovery path.

Copying does not run a command.