Suggested day 620–30 minutesSafe in practice folder

Mission 1 of 5

Redirection Operators

Capture useful output and errors in separate files.

Learn stdin, stdout, stderr, overwrite, append, heredocs, and the safe black hole /dev/null.

Outcome: You can direct command output intentionally instead of feeling surprised by files appearing or changing.

Mental model

Understand what is happening

stdin is input, stdout is normal output, stderr is error output.

> overwrites and >> appends.

2> captures error messages.

Guided lab

Work through the mission

1

Overwrite and append

Safe

Demonstrates the difference between replace and append.

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

Capture errors

Safe

Sends stderr to a file instead of the screen.

Terminal
ls missing-file 2> error.log
cat error.log
3

Use a heredoc

Safe

Creates multi-line text safely.

Terminal
cat << 'EOF' > document.txt
Line 1
Line 2
Variables like $HOME are not expanded here
EOF
cat document.txt

Checkpoint

Verify the mission

Standard output and errors are stored in the intended files.

Try it yourself

One step without a recipe

Create out.txt and err.txt from a command group. Send an error to /dev/null and notice it disappears.

Need a hint?

When a command spews errors you don't care about, send them to `/dev/null` with `2>`. It's Linux's junk drawer — things go in and nothing comes out. Perfect for noisy commands where only the output matters.

Explain it back

Before you move on

  • What does stderr number 2 mean?
  • Which redirect operator appends?

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