Select the TWO true statements about tee and about writing files from a pipeline.

LPIC-1 Exam 101-500, objective 103. GNU and Unix commands hard

Machine-checked — no person has signed for it. This question was read against the source cited below by an automated pass, which found no contradiction. That is a weaker claim than it sounds: the same kind of process wrote the question, so it can confirm its own mistake.

Treat it as a good draft rather than as settled fact, and read the source below before you rely on it. It is not used in mock exams here — only questions a person has signed for are.

How these questions are written — where each question comes from, what the verification ledger records, and what happens when one is found wrong.

The options

Choose 2.

Correct tee -a adds to the named files instead of truncating them.

Correct. Without -a each file is truncated when tee opens it, exactly as a > redirection would do.

Correct tee accepts several file names and writes the same stream to all of them.

Correct. Every operand is a file to duplicate into, so `cmd | tee a.log b.log` fills both while still passing the stream on.

Not correct In `cmd | tee log`, the error messages produced by cmd are captured in log as well.

Wrong. Only standard output enters the pipe; standard error still goes to the terminal unless the pipeline is written `cmd 2>&1 | tee log`.

Not correct tee consumes the stream, so a command placed after it in the pipeline receives nothing.

Wrong. tee writes its input to standard output as well as to the files, which is what makes it usable in the middle of a pipeline.

Not correct In `sudo cmd > /root/out`, the file /root/out is created with root privileges.

Wrong. The redirection is carried out by the shell you are running as an ordinary user, before sudo is executed, so the open fails; `cmd | sudo tee /root/out` is the working form.

Why

tee reads standard input and writes it unchanged to standard output and to each file it is given, which is how a stream is inspected and saved at the same time. Two limits follow from the mechanics: it only ever sees what the pipe carries, namely standard output, and it truncates its files unless -a is used. Because tee opens the files itself, it is also the standard way to write privileged locations from a pipeline.

Where this comes from

Cited
manual page tee(1)

Practise this

Reading one question is not practice. The trainer will draw a short set from objective 103 and space the ones you get wrong.

Practise LPIC-1 Exam 101-500

More questions on this objective

All questions on GNU and Unix commands

Practise LPIC-1 Exam 101-500