Bitpath

Lesson 1 · Unit 02

Three streams

stdout, stderr and stdin, and how >, >>, 2> and | route them

12 exercisesabout 3 min

What you practise

  • Stdin, stdout, stderr
  • >, >>, 2>, 2>&1, <, /dev/null
  • cat, head, tail -f, wc, echo

Try a question from this lesson

Pick one

> sends what a command prints into a file instead of the terminal. Both lines write to the same file. What does cat show?

shell
echo hello > out.txt
echo world > out.txt
cat out.txt

The ideas

Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.

Concept

Three streams

Every command starts with three numbered streams. stdin (0) is its input. stdout (1) carries results. stderr (2) carries complaints.

Both outputs appear on your terminal, which is why they look alike until you redirect one.

> redirects stdout, 2> redirects stderr, and < feeds a file to stdin.

            ┌─────────┐
0 stdin ──▶ │ command │ ──▶ 1 stdout
            └─────────┘ ──▶ 2 stderr

Concept

The pipe

a | b connects the stdout of a straight to the stdin of b. No file in between.

Only stdout goes down the pipe. Errors still reach the terminal.

Three small tools you will pipe into all the time: head keeps the first lines, tail the last ones, and wc -l counts them.

shell
ls /etc | wc -l       # count entries
ls /etc | head -n 3   # first three
tail -n 3 app.log     # last three lines
tail -f app.log       # keep following

9 more exercises in the app

  • 1× fill the blanks
  • 3× multiple choice
  • 3× type the answer
  • 1× true or false
  • 1× order the lines

Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.

One email when Bitpath is ready to try. Nothing else. Privacy