Linux Labs

First steps / Stage 11 of 15

Where a command's output goes

Not running Starting usually ~20 s
Leave the lesson

Step 1 of 6 · on a machine · 5 min

A list of configs

What you will learn

  • Send a command's result and its error messages to separate files.
  • Append output to the end of a file without wiping the lines already there.
  • Collect both streams in one file, or throw the unwanted one away into /dev/null.

A colleague asks for a list of every config in /etc — the files whose names end in .conf. They want a file they can forward. You run a search and send its output to a file with >, as in the lesson on paths.

Exercise · look

Collect the list of configs

You are in ~/stream-lab. Run the three commands in turn: the search written to conf-list.txt, a count of lines with the word denied in that file, and the first three lines of the file.

First, predict

find's output goes to a file. What appears on the screen after the first command?

Now start the exercise, run the command and compare your prediction with the output.

Sign in and start The machine is available after signing in
Check yourself 1 question

Why did the Permission denied messages stay on the screen while conf-list.txt has none of them?

  • File permissions do not depend on which lines are written: the paths made it into conf-list.txt, so student can write to it.

  • > writes whatever text reaches it: echo hello > test.txt writes a word with no /. The messages never reached that text.

  • A file has no limit of a few lines: head showed paths in conf-list.txt, and grep -c denied found not one message there.

The refusal messages went past the file: > redirected the list of paths alone.

Ubuntu 24.04
Loading…