Linux Labs

First steps / Stage 11 of 15

Where a command's output goes

Not running Starting usually ~20 s
Leave the lesson

Step 2 of 6 · on a machine · 6 min

Two output streams

A command has two exits for text: one for the result and one for error messages. On the screen they merge, while > sends only one of them to the file.

A command prints its result to standard output and error messages to standard error. The streams have numbers: output is 1, errors are 2. The terminal shows both streams interleaved, so on the screen you cannot tell them apart.

> is short for 1>: stream 1 goes to the file. Stream 2 is sent to a file with 2>. One command can redirect both streams, each to its own file:

bash
ls /etc/hostname /no-such-file > found.txt 2> missing.txt

The path /etc/hostname ends up in found.txt, the No such file or directory message in missing.txt, and nothing is left on the screen. find prints the same way: the paths it finds go to stream 1, the access refusals to stream 2.

Exercise · do it

Separate the list from the refusals

In ~/stream-lab, find all the configs in /etc again. Write the list of paths to conf-list.txt and the error messages to errors.txt.

Sign in and start The machine is available after signing in

Goals · 0 of 2

  • Write the list of paths to conf-list.txt not done yet
  • Collect the error messages in errors.txt not done yet

Step goals

0 of 2
  • Write the list of paths to conf-list.txt — not done yet
  • Collect the error messages in errors.txt — not done yet
Ubuntu 24.04

Step goals

0 of 2
  • Write the list of paths to conf-list.txt — not done yet
  • Collect the error messages in errors.txt — not done yet
Loading…