Courseiva
Essential Tools →hardMultiple Select

EX200 Essential Tools Practice Question

Which TWO of the following are valid examples of using redirection and pipes in bash to append the output of a command to a file while also displaying it on the terminal? (Choose exactly two.)

⚠ Common exam trap

Red Hat often tests the distinction between `|` (stdout only) and `|&` (stdout and stderr), and the requirement for `-a` to append rather than overwrite, causing candidates to miss that option A lacks `-a` and option D correctly uses `|&` with `-a`.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

✓

command | tee -a file

`tee -a file` reads from stdin and writes both to stdout and appends to the named file. The pipe `|` sends the stdout of `command` to `tee`, so the output is displayed on the terminal and appended to `file`. The `-a` flag ensures append mode, not overwrite.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • ✗

    command 2>&1 | tee file

    Why it's wrong here

    With command 2>&1 | tee file, the shell duplicates file descriptor 2 onto file descriptor 1 before entering the pipe, so stderr and stdout are merged and sent to tee. However, tee file opens the named file in truncation mode, meaning any existing file content is wiped out before the combined stream is written. It does display the combined output on the terminal, but because it overwrites rather than appends, it is not a valid example of the required redirection behavior.

  • ✓

    command | tee -a file

    Why this is correct

    The pipeline command | tee -a file sends only stdout to tee, and the -a flag makes tee open the destination file in append mode, preserving any data already in the file. Tee also writes the same bytes to its own standard output, so the user still sees the command's output live on the terminal. This combination of appending to a persistent log and duplicating the stream to the terminal is exactly what makes it a valid redirection example.

  • ✗

    command > file

    Why it's wrong here

    Using command > file is a plain stdout redirection in which the shell truncates the destination file to zero length before the command even runs, then writes only stdout into that file. It does not append, it does not forward anything to the terminal, and it completely ignores stderr, so it fails both the append and display requirements. Because this overwrites prior content, it is destructive rather than a way to accumulate output over time.

  • ✓

    command |& tee -a file

    Why this is correct

    The |& operator is Bash shorthand for 2>&1 |, so command |& tee -a file merges stderr into stdout and pipes both streams to tee, which then appends the combined data to the named file. The -a flag prevents any truncation, preserving the file's previous contents, while tee still copies the same data to its own stdout and thus to the terminal. This captures both stdout and stderr, appends to the log, and maintains live output, making it a valid redirection approach, though it is Bash-specific and not portable to all shells.

  • ✗

    command >> file

    Why it's wrong here

    The >> operator redirects only stdout, not stderr, and appends output directly to the file; it does not duplicate the data to the terminal or pipe it to any other command. Since tee is absent, there is no mechanism for the user to see the output while it is being logged, so the command silently writes to the file and nothing appears on screen. This option satisfies only the append requirement, and that alone is insufficient for an example that must also display the output.

About these practice questions

This EX200 question is part of Courseiva's 427-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This EX200 practice question is part of Courseiva's free Red Hat certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the EX200 exam.