Display generate-report's output on the terminal.
Create or overwrite primary.log and secondary.log with the same content.
Which command is appropriate?
tee copies standard input to standard output and to each named file. Without -a, the files are overwritten.
Detailed explanation
generate-report > primary.log secondary.logIncorrect. A redirection accepts one target and does not display the output or create a second target this way.
Incorrect. A redirection accepts one target and does not display the output or create a second target this way.
generate-report | tee -a primary.log secondary.logIncorrect. -a appends, but the requirement is to overwrite both files.
Incorrect. -a appends, but the requirement is to overwrite both files.
generate-report | cat primary.log secondary.logIncorrect. cat reads files; it does not write the pipeline input to them.
Incorrect. cat reads files; it does not write the pipeline input to them.
generate-report | tee primary.log secondary.logCorrect. tee displays the stream and overwrites both named files.
Correct. tee displays the stream and overwrites both named files.
Try it yourself
An example you can run in a temporary verification environment.
printf data | tee /tmp/kp-primary.log /tmp/kp-secondary.log; printf '|'; paste -d, /tmp/kp-primary.log /tmp/kp-secondary.log; rm /tmp/kp-primary.log /tmp/kp-secondary.logExpected result
data|data,dataKey points
- tee branches to screen and files
- Multiple output files are allowed
- Without -a files are overwritten
Notes
- Environment: GNU coreutils 9.x
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.