Skip to content
Learn Netverks

Lesson

Step 14/36 39% through track

redirection-bash

Redirection

Last reviewed May 28, 2026 Content v20260528
Track mode
none
Means
Read / quiz
Reading
~1 min
Level
beginner

This lesson

This lesson teaches Redirection: the syntax, patterns, and safety habits you need before advancing in Bash.

Teams still ship Redirection in Bash codebases—skipping it leaves gaps in debugging and code reviews.

You will apply Redirection in contexts like: Batch jobs, log capture, and repeatable deploy scripts checked into Git.

Read each lesson, copy bash examples into your own terminal, and complete the lesson MCQs—there is no in-browser runner for security reasons.

When you can explain the previous lesson's ideas without copying starter code.

Every process has stdin (0), stdout (1), and stderr (2). Redirection connects them to files or pipes.

Stdout and stderr

echo "ok" > out.txt
echo "error" >&2
echo "both" >> out.txt
cat out.txt

> truncates; >> appends. 2> targets stderr.

Combine streams

command 2>&1 | tee log.txt

2>&1 merges stderr into stdout before piping—order matters: 2>&1 after redirecting stdout.

Here string

grep "error" <<< "line1
error: disk
line3"

A here-string feeds a string as stdin—useful for tiny tests without temp files.

Important interview questions and answers

  1. Q: > vs >>?
    A: > truncates the file; >> appends to the end.
  2. Q: What is file descriptor 2?
    A: Standard error—use 2> to capture or discard errors separately.

Self-check

  1. Which operator appends stdout to a file?
  2. How do you send stderr to the same place as stdout before a pipe?

Pitfall: Order matters: 2>&1 after redirecting stdout when merging streams.

Interview prep

> vs >>?

> truncates; >> appends.

2>&1 meaning?

Redirect stderr to wherever stdout currently goes.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • 2>&1 meaning?
  • Append log?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump